iphone - 在 AppDelegate 中以横向模式显示 UILabel

标签 iphone ios objective-c xcode landscape

当推送通知到来时,我在我的 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]

see here

最佳答案

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


                    }

                }

你也可以看看这个changing the lable position based on the orientation .

关于iphone - 在 AppDelegate 中以横向模式显示 UILabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14516944/

相关文章:

ios - 在 UIDatePicker 上设置时间范围

objective-c - WebView 中的 Flash 视频无法在沙盒应用程序中运行

iphone - 以编程方式将设备方向更改为横向不起作用

ios - 动画按钮的最佳方式是什么?

iphone - 检测是否在 Cocos2d-iphone 上触摸了特定的 Sprite

iphone - QuartzCore.framework问题

ios - collectionViewLayout sizeForItemAtIndexPath -> CGSize 奇怪的行为

ios - 在 OSX 上查看文档集

objective-c - MFMailComposeViewController : cancel doesn't exit to my app?

iphone - 不使用 UIImage 添加复杂的动画