2011年6月17日 星期五

Detect the orientation of iPhone view

step 1: add a notification

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



step 2: remove a notification

    [[NSNotificationCenter defaultCenter] removeObserver:self  
                             name:UIDeviceOrientationDidChangeNotification 
                           object:nil];


step 3: implement "receiveRotate"

- (void)receivedRotate:(NSNotification*)notification
{
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
    if (deviceOrientation == UIDeviceOrientationPortrait)
    {
        ...
    }
}

沒有留言:

張貼留言