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