开发者

iPad back button stops working on rotate

I am developing a iphone/ipad app.

Problem is that when i change the orientation of ipad portrait to Landscape, back button of navigation controller stops working.

It"s work fine when orientation not changed.

i am using this code

 - (BOOL) isPad{    
 #ifdef UI_USER_INTERFACE_IDIOM
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
 #else
    return NO;
 #endif
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interf开发者_运维问答aceOrientation
{
// Return YES for supported orientations
if ([self isPad]) {
    return YES;
}
else 
{
    return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}

}

What"s the wrong with this code?


This will work :

-(void)viewWillAppear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivedRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

}

-(void)viewWillDisappear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
}  

Now implement the following method :

-(void)checkOrientation
{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIDeviceOrientationLandscapeLeft||orientation==UIDeviceOrientationLandscapeRight)
{

    // Set x coorinate of views you want to change

}
else
{

    // Set x coordinates of views to initial x xoordinates.

}

}  

Create recievedRotate :

- (void)receivedRotate:(NSNotification *)notification
{    
[self checkOrientation];
}  

In viewDidLoad :

-(void)viewDidLoad
{  
// Code    
[self checkOrientation];
}


My guess is that your button is out of the view's frame and thus won't receive touch events. I think something is wrong with the way your app redraws on orientation change.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜