【发布时间】:2016-09-07 04:47:58
【问题描述】:
我知道这个问题可能已经回答了好几次了,但是,我确实尝试了在 StackOverflow 上可以找到的所有可能的东西,但没有成功。
基本上,我有这样初始化的自定义 UIView 类:
MyUIView *test = [[MyUIView alloc] initWithFrame:self.view.bounds];
然后,我有一个 NSTimer 计划在 5 秒内通过这个调用关闭:
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
if (!self.isRotated) {
self.isRotated = YES;
appDelegate.allowLandscape = YES;
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationLandscapeLeft] forKey:@"orientation"];
}else{
self.isRotated = NO;
appDelegate.allowLandscape = NO;
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationPortrait] forKey:@"orientation"];
}
基本上是这样的:
-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
if (self.allowLandscape) {
return UIInterfaceOrientationMaskLandscapeLeft;
}else{
return UIInterfaceOrientationMaskPortrait;
}
}
如果我只是在viewDidLoad 方法中将self.allowLandscape 设置为YES,它就可以正常工作。但是,如果我在延迟 5 秒后调用 NSTimer 方法,则 UIView 不会被转换为 LandscapeLeft。
我可以通过使用约束来解决这个问题,但是,在这个项目中,我只使用程序化大小。
【问题讨论】:
标签: ios objective-c mobile view resize