2011-06-20 25 views
1

我正在开发iPhone/iPad应用程序。iPad后退按钮停止旋转工作

问题是,当我将ipad肖像的方向更改为横向时,导航控制器的后退按钮停止工作。

它“的工作很好,当没有改变方向。

我使用这个代码

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

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
// Return YES for supported orientations 
if ([self isPad]) { 
    return YES; 
} 
else 
{ 
    return UIInterfaceOrientationIsPortrait(interfaceOrientation); 
} 

} 

什么”发错用此代码?

回答

1

这将工作:

-(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]; 
} 

现在实现以下方法:

-(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. 

} 

} 

创建recievedRotate:

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

在viewDidLoad中:

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

这可以工作,但是也可以在UIView及其组件上设置正确的AutoResizingMask值。最好是通过Interface Builder来完成,但可以通过程序设置。 – Jake

0

我的猜测是你的按钮超出了视图的框架,因此不会收到触摸事件。我认为你的应用重新定位方向改变的方式有些问题。