shouldAutorotateToInterfaceOrientation无法正常工作(shouldAutorotateToInterfaceOrientation doesn't wor

编程入门 行业动态 更新时间:2024-10-22 19:31:03
shouldAutorotateToInterfaceOrientation无法正常工作(shouldAutorotateToInterfaceOrientation doesn't work properly)

如果设备是iPhone,我想锁定方向为肖像,如果设备是iPad,我想允许所有方向。

我有这个代码,但它不会在纵向模式下锁定iPhone:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { return NO; } else { if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) return YES; } return NO; }

问题是什么?

I want to lock orientation to Portrait if device is iPhone, and allow all orientations if the device is iPad.

I have this code, but it doesn't lock iPhone in Portrait mode:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { return NO; } else { if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) return YES; } return NO; }

What is the problem?

最满意答案

if you will navigate the view then force orientation will not work but if you will present your view then it will work very well and it works for me. In my project all screens are in portrait mode only but only one screen is in landscape mode. - (IBAction)startButtonClicked:(id)sender { CTFailure_RemedyGameViewController *remedyGameController = [[CTFailure_RemedyGameViewController alloc]initWithNibName:@"CTFailure_RemedyGameViewController" bundle:nil]; [self presentModalViewController:remedyGameController animated:NO]; [remedyGameController release]; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); } @end if you will navigate the view then force orientation will not work but if you will present your view then it will work very well and it works for me. In my project all screens are in portrait mode only but only one screen is in landscape mode. - (IBAction)startButtonClicked:(id)sender { CTFailure_RemedyGameViewController *remedyGameController = [[CTFailure_RemedyGameViewController alloc]initWithNibName:@"CTFailure_RemedyGameViewController" bundle:nil]; [self presentModalViewController:remedyGameController animated:NO]; [remedyGameController release]; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); } @end

更多推荐

本文发布于:2023-08-07 20:12:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465555.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:无法正常   工作   shouldAutorotateToInterfaceOrientation   work   properly

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!