【问题标题】:Scroll View content size in Universal app?在通用应用程序中滚动查看内容大小?
【发布时间】:2014-01-10 20:30:27
【问题描述】:

我不确定如何为通用应用设置不同的滚动条尺寸。

到目前为止,我在 iPhone 尺寸的实现文件中有以下代码,但不确定如何为 iPad 滚动条尺寸编写代码。

- (void)viewDidLoad {
    [self.navigationController setNavigationBarHidden:NO animated:NO];
    [super viewDidLoad];

[ScrollerInstructions setScrollEnabled:YES];
[ScrollerInstructions setContentSize:CGSizeMake(300, 2000)];

}

谢谢!

【问题讨论】:

    标签: ios uiscrollview scroll scrollview universal


    【解决方案1】:

    使用这个,所以你可以根据设备设置contenSize:

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
        // iPad contentSize
        [ScrollerInstructions setContentSize:CGSizeMake(600, 3000)];
    } else if ([[UIScreen mainScreen] bounds].size.height >= 568) {
        // iPhone 5/5s contenSize
        [ScrollerInstructions setContentSize:CGSizeMake(300, 2500)];
    } else {
        // old iPhone contenSize
        [ScrollerInstructions setContentSize:CGSizeMake(300, 2000)];
    }
    

    一个好的使用方法是,将其设置为您的 .pch 文件中的定义,如下所示:

    #define IS_IPAD ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
    #define IS_IPHONE5 (!IS_IPAD && ([[UIScreen mainScreen] bounds].size.height >= 568))
    

    这样您就可以简单地在源代码中使用:

    if (IS_PAD) {
    
    } else if (IS_IPHONE5) {
    
    }
    

    【讨论】:

    • 非常感谢!我忘了问关于 iphone5 以及上面的内容会有什么不同。
    • 再次非常感谢您!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多