如何在iPhone应用程序中使UIScreen边界景观

时间:2013-07-16 07:28:52

标签: ios ipad uiview uiscreen

我在主视图上制作subView它工作正常但问题是,当我添加任何东西时它需要肖像边界虽然我的应用程序是横向模式我想要的横向模式。

这是我的代码

 backgroundViewBounds= [[UIScreen mainScreen] bounds];

 backgroundView = [[UIView alloc]initWithFrame:backgroundViewBounds];
 [self.view.window addSubview:backgroundView] ;

 CGRect subViewBounds = CGRectMake(0,0,1100,1100) ;
 subView=[[UIView alloc]initWithFrame:subViewBounds];

 subView.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"bgPopupback"]];

 [backgroundView addSubview:subView] ;


 UIImageView*popImageView=[[UIImageView alloc] initWithFrame:CGRectMake(600,745,165,108)];


popImageView.image=[UIImage imageNamed:@"popup3.png"];

[popImageView setTransform:CGAffineTransformMakeRotation(-M_PI / 2)];

[subView addSubview:popImageView];

我已经搜索了这个但是没有得到任何工作,有些人说在veiwWillappear使用但没有和我一起工作。

2 个答案:

答案 0 :(得分:0)

我使用orientation来查看如何解释UIScreen大小:

UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
        if (orientation!=UIDeviceOrientationPortrait) {

            int width = screenRect.size.height;
            int height = screenRect.size.width;
            screenRect.size.height = height;
            screenRect.size.width = width;

            backgroundView.frame = screenRect;
        }
        else{
            backgroundView.frame = screenRect;
        }

答案 1 :(得分:0)

如果您想在旋转添加时更改屏幕方向:

[[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(deviceOrientationDidChangeNotification:)
     name:UIDeviceOrientationDidChangeNotification
     object:nil];

通知女巫代码在方向改变时运行。

我的deviceOrientat

- (void)deviceOrientationDidChangeNotification:(NSNotification*)note
{
UIView * backgroundView = [self viewWithTag:10];
CGRect screenRect = [[UIScreen mainScreen] bounds];
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation!=UIDeviceOrientationPortrait) {

    int width = screenRect.size.height;
    int height = screenRect.size.width;
    screenRect.size.height = height;
    screenRect.size.width = width;

    backgroundView.frame = screenRect;
    mainView.center = backgroundView.center;
}
else{
    backgroundView.frame = screenRect;
    mainView.center = backgroundView.center;
}
}

希望有所帮助