开发者

generatesDeviceOrientationNotifications

I have seen this property in UIDevice.h file generatesDeviceOrien开发者_如何学运维tationNotifications how can i benefit from this or how can i use it or how it generate notification is it generate alert view


You can ask the UIDevice to generate device orientation notifications:

UIDevice *myDevice = [UIDevice currentDevice]; 
[myDevice beginGeneratingDeviceOrientationNotifications]; 

Your UIViewController subclasses can listen for this notification by doing this:

[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(didRotate:)
                                             name:UIDeviceOrientationDidChangeNotification
                                           object:nil];

and writing a didRotate: method like this:

- (void)updateOrientation 
{
    UIInterfaceOrientation orientation = self.interfaceOrientation;
// handle new orientation
...
}


- (void)didRotate:(NSNotification *)notification 
{
    [self updateOrientation];
}

The benefits to doing this over the "standard"

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration

is that sometimes, based on the structure and nesting of your UIViewControllers, you may not always receive the willAnimateRotationToInterfaceOrientation calls. Handling the notification instead guarantees that your ViewControllers which need to handle the changes always know when the change happens.


missing an * :

UIDevice * myDevice = [UIDevice currentDevice];

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜