0

I am showing a custom UILabel in my appdelegate class when a push notification comes. It is working fine in Portrait mode but when i rotate my device to landscape mode, label is still showing in Portrait mode. How can i fix it. I have implement rotation method. But it did not worked. Thanks in advance.

My code is :

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {   
CGRect frame=[[UIApplication sharedApplication] statusBarFrame];
 if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft
                || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight) {

                 backgroundImageView=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 480, 32)]; 
            } else {
                backgroundImageView=[[UILabel alloc] initWithFrame:CGRectMake(0, frame.size.height, 320, 44)];   
                NSLog(@"portrait");   
            }
[backgroundImageView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"alert.png"]]];
backgroundImageView.userInteractionEnabled=YES;
UITapGestureRecognizer *tgr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(click:)];  
            [backgroundImageView addGestureRecognizer:tgr];  
[self.window addSubview:backgroundImageView];
 }![enter image description here][1]

see here

4

4 回答 4

1
I have done the similar kind of thing using the following code...

   - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation       duration:(NSTimeInterval)duration {

                    [self adjustUrLableViewForOrientation:toInterfaceOrientation];

                }

              -(void) adjustUrLableViewForOrientation:(UIInterfaceOrientation)orientation
                {
                 if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
                    {
                        //Ur lable portrait view
                    }
                    else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
                    {

                  //Ur lable for landscape view


                    }

                }

您也可以根据方向研究更改标签位置

于 2013-01-25T07:14:32.353 回答
0
[backgroundImageView setTransform:CGAffineTransformMakeRotation(M_PI/2.0)];

应该适用于这种情况

于 2013-01-25T07:32:12.613 回答
0

UiWindow subviews不要自己旋转..你需要检查设备旋转变化这样

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

然后在方法中..根据当前方向手动旋转标签。

于 2013-01-25T07:05:50.203 回答
0
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 return (interfaceOrientation == UIInterfaceOrientationPortrait ||
   interfaceOrientation == UIInterfaceOrientationLandscapeLeft || 
   interfaceOrientation == UIInterfaceOrientationLandscapeRight ||
   interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown );
} 

添加这个...希望这有帮助..

或者添加这个:

- (BOOL)shouldAutorotate{
   return YES;
}

- (NSUInteger)supportedInterfaceOrientations{
  return UIInterfaceOrientationPortrait || UIInterfaceOrientationLandscapeLeft || UIInterfaceOrientationLandscapeRight || UIInterfaceOrientationPortraitUpsideDown ;
}
于 2013-01-25T07:09:22.327 回答