事件 willAnimateRotationToInterfaceOrientation 没有调用 [英] Event willAnimateRotationToInterfaceOrientation isn't calling

查看:15
本文介绍了事件 willAnimateRotationToInterfaceOrientation 没有调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序上有几个 UIViewController.但只有其中一个 willAnimateRotationToInterfaceOrientation 事件正在调用.

I have several UIViewControllers on the application. But only on one of them willAnimateRotationToInterfaceOrientation event is calling.

如何使 willAnimateRotationToInterfaceOrientation 适用于所有可见视图?

How to make willAnimateRotationToInterfaceOrientation work for all visible views?

推荐答案

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];
}

这篇关于事件 willAnimateRotationToInterfaceOrientation 没有调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆