原问题来自于CSDN问答频道,更多解决方案见:http://ask.csdn.net/questions/2108
问题描述:
在应用中有几个UIViewController。其中一个willAnimateRotationToInterfaceOrientation 事件调用成功了。
如何让willAnimateRotationToInterfaceOrientation对所以可见视图有效?
解决方案:
RootViewController中:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
NSDictionary *userInfo = @{
@"toInterfaceOrientation":@(toInterfaceOrientation),
@"duration":@(duration)};
[[NSNotificationCenter defaultCenter] postNotificationName:@"willAnimateRotationToInterfaceOrientation" object:nil userInfo:userInfo];
}
其他的 UIViewControllers:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willAnimateRotationToInterfaceOrientation:) name:@"willAnimateRotationToInterfaceOrientation" object:nil];
}
return self;
}
- (void)willAnimateRotationToInterfaceOrientation:(NSNotification *)notification {
UIInterfaceOrientation toOrientation = (UIInterfaceOrientation)[notification.userInfo[@"toOrientation"] intValue];
NSTimeInterval duration = (UIInterfaceOrientation)[notification.userInfo[@"duration"] floatValue];
[self willAnimateRotationToInterfaceOrientation:toOrientation duration:duration];
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {
// ...
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
本文介绍了一种在iOS应用中实现所有可见视图控制器响应屏幕旋转事件的方法。通过在根视图控制器发布旋转通知,并让其他视图控制器监听这些通知来同步旋转行为。

254

被折叠的 条评论
为什么被折叠?



