IOS 6 View Controller 不正确的宽度/边界 - 横向模式

标签 ios iphone objective-c

我的应用同时使用横向模式和纵向模式,用户可以随意在两者之间切换。

当 View Controller 由处于纵向方向的父 View Controller 呈现时,打开的 View Controller 将具有正确的宽度和框架

但是,如果父 View Controller 处于横向模式,那么在 IOS6 上(它在 IOS7 上可以正常工作), subview Controller 将太大并且实际上呈现时也有点太短了。

请注意,这不是因为值报告不正确,因为 [[UIScreen mainScreen] bounds] 报告相同的值,而不 pipe Controller 加载的方向如何。

关于如何解决这个问题/为什么会发生这种情况的任何想法?关于如何强制 IOS6 版本表现得像 IOS7 现在 native 表现的任何想法?非常感谢!!!

编辑:: 以下是 vc 的呈现方式:

应用委托(delegate)

Launch1 *launch1 =[[Launch1 alloc] init];
self.window.rootViewController = launcher;
[self.window makeKeyAndVisible];

Launch1 类

Search *search = [[Search alloc] init];
[self presentViewController:search animated:YES completion:nil];

搜索类

//load list_container
views = [[Search_custom_views alloc] initWithControllerContext:self];
[self.view addSubview:views];

Search_custom_views UIView 扩展:

- (id)initWithControllerContext:(UIViewController*)contextstart {

    //set size of the screen
    CGRect screenRect = [[UIScreen mainScreen] bounds];

    self = [super initWithFrame:screenRect];

    if (self) {
     ....

最佳答案

所以这是一个艰难的过程。我以编程方式加载所有 View 。它们基本上是对应于每个 View Controller 的 UIView 子类。出于某种原因,当在横向模式下从父 View Controller 打开 IOS6 View Controller 时, subview Controller 的边界不会立即传递给子 vc 的 UIView 子类(如果您只是在 Controller 的 viewDidLoad 方法中使用 addSubview -那还不够)。 IOS7没有这个问题。

对我来说,IOS6 的修复是在 subview Controller 的 viewDidLoad 方法中执行以下操作:

//add view subclass to view controller
[self.view addSubview:views];

//reset bounds & refresh layout for IOS6
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 7) {
    views.frame = self.view.bounds;
    [views layoutIfNeeded];
}

关于IOS 6 View Controller 不正确的宽度/边界 - 横向模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19576253/

相关文章:

objective-c - 如何将 SEL 传递给 dispatch_async 方法

iphone - 将对象存储到 NSMutableArray

ios - 如何在调试时使用 2 种语言而在生产时只使用 1 种语言?

iphone - 在 Objective-C 中对数组进行排序

ios - (Cocos2D) Child 已经添加了 CCMenuItemImage?

iphone - 关于在 iOS 和 Android 上开发多人游戏的建议?

iphone - 圆形蒙版效果

ios - 未为所有部分调用 cellForRowAtIndexPath

iphone - 如何减小从 cam 捕获的图像尺寸

ios - SSKeychain 凭证存储设置不正确?