• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - UIScrollView 3.5英寸屏幕

[复制链接]
菜鸟教程小白 发表于 2022-12-13 07:28:14 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我为 iPhone 创建了一个应用程序,它非常适合 iPhone 5/5S/5C 屏幕。但是,我尝试在 iPhone 4/4S(较小的屏幕)上使用 ScrollView。

我的 View 嵌入在导航栏 Controller 中,也位于标签栏 Controller 中。我的 ScrollView 位于两者之间的空间中,当它位于 iPhone 5/5S/5C 中时,我不希望它滚动,因为它已经是完美的尺寸了。这部分工作正常。

但是,当我在模拟器上以较小的屏幕尺寸测试它时,我希望它能够滚动,但它根本不滚动。

我的 ScrollView 有一个 IBOutlet,我在 .m 文件中使用以下代码行来设置 ScrollView 。

if (self.view.bounds.size.height == 568)
{
    [_Scroller setContentSize:CGSizeMake(320, 1500)];
    _Scroller.frame = CGRectMake(0, 64, 320, self.view.bounds.size.height);
}
else
{
    [_Scroller setContentSize:CGSizeMake(320, 80)];
    _Scroller.frame = CGRectMake(0, 64, 320, self.view.bounds.size.height);
}

_Scroller.keyboardDismissMode = UIScrollViewKeyboardDismissModeInteractive;
[_Scroller setScrollEnabled:YES];

我的 View Controller 中的 Adjust Scroll View Insets 也未勾选,因为它一直在 ScrollView 的顶部添加一个恼人的间隙。

谁能帮我解决我哪里出错了?它快把我逼疯了!任何帮助都会很棒。我对 iOS 开发也很陌生。

谢谢各位!

编辑:

我已经把 if 语句改成了这个,但还是不行:

if (self.view.bounds.size.height == 568)
{
    [_Scroller setContentSize:CGSizeMake(320, 1500)];
    _Scroller.frame = CGRectMake(-4, 64, 329, self.view.bounds.size.height);
}
else
{
    [_Scroller setContentSize:CGSizeMake(320, 2000)];
    _Scroller.frame = CGRectMake(-4, 64, 329, self.view.bounds.size.height);
}

_Scroller.keyboardDismissMode = UIScrollViewKeyboardDismissModeInteractive;
[_Scroller setScrollEnabled:YES];



Best Answer-推荐答案


这样使用:

if ([[UIScreen mainScreen] bounds].size.height >= 568) //iphone 5/5c/5s/6/6 plus
{
  //making ContentSize and frame's height same as not need of scrolling
  //make changes in height if necessary
  [_Scroller setContentSize:CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height-64)]; 
  //make changes in height if necessary
  _Scroller.frame = CGRectMake(0, 64, self.view.bounds.size.width, self.view.bounds.size.height-64); 
}
else //iphone 4/4s
{
   //making ContentSize greater than frame's height as we need scrolling
   //make changes in height if necessary
   [_Scroller setContentSize:CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height+64)]; 
   if([[UIDevice currentDevice].systemVersion hasPrefix"7"]) //iOS 7.0 >
   {
     //made changes in y as status bar height is counted
     _Scroller.frame = CGRectMake(0, 64, self.view.bounds.size.width, self.view.bounds.size.height-64);
   }
   else //iOS 6.1 <
   {
      //made changes in y as status bar height not counted
      _Scroller.frame = CGRectMake(0, 44, self.view.bounds.size.width, self.view.bounds.size.height-64);
   }
}

关于ios - UIScrollView 3.5英寸屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23080276/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap