當推送通知出現時,我在我的appdelegate類中顯示自定義UILabel。它在肖像模式下工作正常,但是當我將設備旋轉到橫向模式時,標籤仍然以肖像模式顯示。我如何解決它。我已經實現了旋轉方法。但它沒有奏效。提前致謝。在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]
它在環去工作,如果([[UIApplication的sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft || [[UIApplication的sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight){}但在橫向模式下不顯示標籤 – shivam
您必須在標籤上應用CGAffineTransform才能將其旋轉90度 – Shubhank
CGAffineTransform在此處不起作用。標籤顯示在屏幕上的未知位置,而不是正確的位置。 – shivam