如何让willAnimateRotationToInterfaceOrientation对所有可见视图有效?

问答小助手 2013-04-18 11:02:55
加精
原问题来自于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];
}
...全文
2261 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
凛然。 2015-09-13
  • 打赏
  • 举报
回复
系统就有旋转通知的
何鑫紈 2013-04-24
  • 打赏
  • 举报
回复
banxiepifa 2013-04-23
  • 打赏
  • 举报
回复
u010363242 2013-04-19
  • 打赏
  • 举报
回复
暗杀
bangguox 2013-04-19
  • 打赏
  • 举报
回复
不会,帮顶下

29,027

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧