简体   繁体   English

从横向到纵向无法在ipad中使用?

[英]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.

相关问题 ipad:横向和纵向方向的问题 - ipad: problem in landscape and portrait orientation 支持iPhone上的纵向方向的通用应用程序和iPad上的横向+纵向 - Supporting Universal App with Portrait Orientation on iPhone and Landscape+Portrait on iPad iPad-横向模式不适用于iPad,但适用于模拟器 - iPad - landscape orientation is not working on iPad, but working in simulator 方向改变从横向到纵向的工作都很奇怪 - orientation change working strangely from landscape to portrait 方向风景->人像不起作用 - Orientation Landscape -> Portrait isn't working 仅横向使用iPad应用程序以纵向显示UIImagePicker - Landscape only iPad app displays UIImagePicker in portrait orientation iPad - 根据设备方向更改图像(纵向或横向) - iPad - Change image depending on device orientation (Portrait or Landscape) 正确缩放图像和按钮方向以适用于横向和纵向模式的iPad - scale image and button orientation correctly for landscape and portrait mode ipad 纵向 iPhone 应用程序在 iPad 上以横向启动时出现错误边界 - Wrong bounds when portrait iPhone app launched on iPad with landscape orientation 方向肖像和风景模式 - Orientation portrait and landscape mode
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM