程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> ios-iphone中事件沒有被調用

ios-iphone中事件沒有被調用

編輯:編程綜合問答
iphone中事件沒有被調用

在應用中有幾個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];
}
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved