[英]Landscape to portrait orientation not working in ipad?
I have used following methods for changing the orientation but it doesn't calls. 我使用以下方法更改方向,但未调用。 Why it's so?
为什么会这样呢?
-(void)viewWillAppear:(BOOL)animated
{
if(self.interfaceOrientation==UIInterfaceOrientationPortrait||self.interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown)
{
[self potraitFrame];
}
else
{
[self landScapeFrame];
}
}
//Auto Rotating Methods //自动旋转方法
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
BOOL returnval=NO;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
if(interfaceOrientation==UIInterfaceOrientationPortrait||interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown)
{
[self potraitFrame];
}
else
{
[self landScapeFrame];
}
returnval = YES;
}
return returnval;
}
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
if(toInterfaceOrientation==UIInterfaceOrientationPortrait||toInterfaceOrientation==UIInterfaceOrientationPortraitUpsideDown)
{
[self potraitFrame];
}
else
{
[self landScapeFrame];
}
}
}
-(BOOL)shouldAutorotate
{
return YES;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
// UIInterfaceOrientation crntOrntatn = self.interfaceOrientation;
// return UIInterfaceOrientationIsLandscape(crntOrntatn) ? crntOrntatn : UIInterfaceOrientationLandscapeLeft;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
return self.interfaceOrientation;
}
}
-(NSUInteger)supportedInterfaceOrientations
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
return UIInterfaceOrientationMaskAll;
}
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration
{
[super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft
|| toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
Nslog(@"Landscape");
}
else
{
Nslog(@"Potrait");
}
}
this code it will be use full for rotation....and u can write in viewwillappear like this
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if(orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
{
//Do your stuff for landscap
} else if(orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
{
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.