ios - 如何对 UIView 进行自定义布局,使其适用于 iPhone 5 屏幕尺寸以及常规屏幕尺寸

标签 ios objective-c layout autoresizingmask contentmode

这是期望的结果。蓝色区域是感兴趣的 UIView。 UIView 不是 UIImageView。

enter image description here

我已经尝试了各种自动调整大小蒙版的安排,但没有成功

最佳答案

这只能通过编程来完成。一种选择是 @user2223761 建议的子类化。如果您不想子类化 UIView,则需要在方向更改时设置框架并将 yourView.center 设置为中心的中心。

- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {

   if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
          // Make sure that the frame is centered in the screen
          NSInteger paddingLeftSide = (self.view.bounds.size.width - 480) / 2;
          self.view.frame = CGRectMake(paddingLeftSide, 0, 480, 320);   
      } else {
          self.view.frame = CGRectMake(0, 0, 320, 320);
      }
  }

关于ios - 如何对 UIView 进行自定义布局,使其适用于 iPhone 5 屏幕尺寸以及常规屏幕尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15677544/

相关文章:

android - 如何通过代码更改 Android SlidingDrawer 的方向?

ios - 动态输入文本时如何生成自动文本字体更改?

ios - Google 登录在 iOS 中不起作用 - 无效的 GOOGLE_APP_ID 错误

objective-c - NSKeyedArchiver 不保存对象的所有属性

java - 我的 TableLayout 中的项目没有在 Eclipse 中排列

css - 如何修复 jQuery UI 自动完成/组合框布局?

用于复杂设计和架构的 IOS 静态库

ios - 删除 UITextView 上带有 alpha 动画的 CAGradientLayer

javascript - 在 NSString 上运行 Javascript

ios - UITabBarController 中的 TableView 内容插入