0

I am making subView on the main view it works fine but problem is that when i add any thing in it it takes portrait bounds though my app is landscape mode i want in landscape mode.

here is my code

 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];

I have searched for this but did not get any working some say use in veiwWillappear but not working with me.

Jan Developer
  • 45
  • 1
  • 1
  • 5

2 Answers2

0

I use orientation to see how to interpret the UIScreen size:

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;
        }
  • In your code backgroundViewBounds is screen rect. Then check screen orientation. If it is portrait than switch height and width. –  Jul 16 '13 at 07:49
  • the code you already has will show subview on screen backgroundView = [[UIView alloc]initWithFrame:backgroundViewBounds]; [self.view.window addSubview:backgroundView] ; My code is just to properly calculate backgroundViewBounds –  Jul 16 '13 at 07:56
  • i have did like this it again takes portrait bounds – Jan Developer Jul 16 '13 at 07:58
  • So if I understand correctly you would like to change when rotating –  Jul 16 '13 at 08:00
0

if you would like to change orientation of the screen while rotating add:

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

to inform witch code to run when orientation is change.

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

Hope it help