0

我在主视图上制作 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 中使用但没有与我一起工作。

4

2 回答 2

0

我使用方向来查看如何解释 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;
        }
于 2013-07-16T07:31:47.357 回答
0

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

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

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

我的设备方向

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

希望有帮助

于 2013-07-16T08:24:27.333 回答