iDev : Orientation Notification

Way is :
/********************************* Notification For Orientation ***************************************/

#pragma mark – Orientation Notification
#pragma mark callNotification

 
-(void)changeOrientationsNotification{
    
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver: self
                                             selector: @selector(orientationWillChange:)
                                                 name: UIApplicationWillChangeStatusBarOrientationNotification
                                               object: nil];
}
 

#pragma mark – orientationWillChange

 
– (void)orientationWillChange: (NSNotification *) note
{
 
UIInterfaceOrientation orientation = [[[note userInfo] objectForKey: UIApplicationStatusBarOrientationUserInfoKey] integerValue];
 
    if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight){
[self shouldAutorotateToInterfaceOrientation:orientation];
//NSLog(@”Landscape”);
}else {
[self shouldAutorotateToInterfaceOrientation:orientation];
//NSLog(@”Portrait”);
}
}
/*********************************Orienation closed***************************************/
 

 
#pragma mark – Orientation Code For iOS6
/************** ORIENTATION CODE FOR IOS 6 START **************************/
 
-(BOOL)shouldAutorotate
{
    return YES;
}
 
-(NSUInteger)supportedInterfaceOrientations
{
    UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
 
    if (orientation == UIInterfaceOrientationLandscapeLeft || orientation ==UIInterfaceOrientationLandscapeRight){
[self shouldAutorotateToInterfaceOrientation:orientation];
//NSLog(@”Landscape”);
}else {
[self shouldAutorotateToInterfaceOrientation:orientation];
//NSLog(@”Portrait”);
}
    
    return UIInterfaceOrientationMaskAll;
}
 
 
/************** ORIENTATION CODE FOR IOS 6 END **************************/
 
 
Calling Procedure :
     [self performSelector:@selector(changeOrientationsNotification)];

Keep Coding… 🙂

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s