gpt4 book ai didi

objective-c - ios强制设备旋转

转载 作者:行者123 更新时间:2023-12-01 18:32:15 24 4
gpt4 key购买 nike

这是我的代码:

  if ([[UIApplication sharedApplication] statusBarOrientation] != UIInterfaceOrientationLandscapeLeft) {
[appDelegate makeTabBarHidden:TRUE];
self.navigationController.navigationBarHidden = YES;
[UIView beginAnimations:@"newAlbum" context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(addResultGraph)];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:YES];
// Then rotate the view and re-align it:
CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation( 90.0 * M_PI / -180.0 );
landscapeTransform = CGAffineTransformTranslate( landscapeTransform, +90.0, +90.0 );
[self.navigationController.view setTransform:landscapeTransform];
[UIView commitAnimations];
}

这样,从肖像模式开始,新的viewcontroller会以landscapeleft模式显示,并且一切正常,但是我的问题是:如果我以纵向模式从横向模式旋转设备,则状态栏会以纵向模式出现,而viewcontroller仍处于横向模式...

我该如何解决?
提前致谢!

最佳答案

您可以重新实现shouldAutorotateToInterfaceOrientation方法并执行类似的操作

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

这样,您只能启用向左方向,并且如果将设备旋转为纵向,界面将不会旋转

关于objective-c - ios强制设备旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7501891/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com