0

プッシュ通知が来ると、appdelegate クラスでカスタム UILabel を表示しています。ポートレート モードでは正常に動作していますが、デバイスをランドスケープ モードに回転すると、ラベルがポートレート モードのまま表示されます。どうすれば修正できますか。ローテーションメソッドを実装しました。しかし、うまくいきませんでした。前もって感謝します。

私のコードは次のとおりです。

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

ここを参照

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

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 に答える
0
[backgroundImageView setTransform:CGAffineTransformMakeRotation(M_PI/2.0)];

この場合はうまくいくはずです

于 2013-01-25T07:32:12.613 に答える