0

我正在为 ipad 开发应用程序,纵向图像工作正常,但是当我切换到横向时,它聚集的屏幕,有没有办法管理这两个图像或自动调整。

4

2 回答 2

0

in .m file do things according to current orientation

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged) name:@"UIDeviceOrientationDidChangeNotification" object:nil];

-(void)orientationChanged {


    UIDeviceOrientation   orientation = [UIDevice currentDevice].orientation;

    CGRect screenBounds = [[UIScreen mainScreen] bounds];

    if(orientation == UIInterfaceOrientationLandscapeLeft)
    {

        if ([[UIDevice currentDevice] userInterfaceIdiom] ==UIUserInterfaceIdiomPhone)
        {
            if (screenBounds.size.height == 568) {
               //for iphone 5 LandscapeLeft
            } else {
               //for iphone 4 LandscapeLeft
            }
        }
        else
        {
            //for ipad LandscapeLeft
        }

    }
    else if(orientation == UIInterfaceOrientationLandscapeRight)
    {
        if ([[UIDevice currentDevice] userInterfaceIdiom] ==UIUserInterfaceIdiomPhone)
        {
            if (screenBounds.size.height == 568) {
                // for iphone 5 LandscapeRight
            } else {
               // for iphone 4 LandscapeRight
            }
        }
        else
        {
            //for ipad LandscapeRight
        }


    }
    else if(orientation == UIInterfaceOrientationPortrait)
    {
        //do change in design when ios change
        if ([[UIDevice currentDevice] userInterfaceIdiom] ==UIUserInterfaceIdiomPhone) {
            if (screenBounds.size.height == 568) {

                // for iphone 5 Portrait
            } else {
                // for iphone 4 Portrait
            }
        } else {
            //for ipad Portrait
        }
    }
    else if(orientation == UIInterfaceOrientationPortraitUpsideDown)
    {
        //Do what you want in Portrait Upside Down
      if ([[UIDevice currentDevice] userInterfaceIdiom] ==UIUserInterfaceIdiomPhone) {
            if (screenBounds.size.height == 568) {
                // for iphone 5 PortraitUpsideDown

            } else {
              // for iphone 4 PortraitUpsideDown  
            }
        } else {
            //for ipad PortraitUpsideDown
        }
    }
}

orientationChanged method called whenever your divice change orientation. than you can set image according to your new orientation. and yes you have to create your image for two orientation portrait and landscap.

于 2013-05-30T07:20:58.210 回答
0

有选择: -

1)如果 ios 6 你可以使用 autolayout 。2)您可以单独为uicontrols设置框架,如果ios 6可以使用这两种方法

-(BOOL)shouldAutorotate
{
    return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationLandscapeLeft ;//return UIInterfaceOrientationMaskAll;
}

然后在 ViewDidlOAd() 和 viewWillAppear() 中需要的任何地方执行此操作

 if(UIInterfaceOrientationIsPortrait([UIApplication sharedApplication ]statusBarOrientation))
{
// change frames
}
else
{
// for landscape change frames here
}

iOS < 6.x

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation // Deprecated in iOS 6.x 
{
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
于 2013-05-30T07:22:51.810 回答