作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的应用程序支持所有方向,但在少数情况下我想锁定屏幕
纵向/横向模式。
在我的应用程序中,我有两种 pdf 文档。
一个是纵向文档,另一个是横向文档。
我只想在纵向 View 中打开纵向文档,而在横向文档中打开
仅限横向 View 。
我想这样做:如果我的应用程序在横向 View 中打开并且我单击
纵向文档,因此它必须在纵向 View 中旋转,如果横向,则与此相同
我的应用程序以纵向 View 打开,当我单击横向文档时它
必须旋转或只能横向打开文档。
希望我让你们明白请原谅我的英语希望你们明白我想要什么
需要你的帮助。
提前致谢
这是我的一些代码:
- (void)viewDidLoad
{
[super viewDidLoad];
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait || orientation ==
UIInterfaceOrientationPortraitUpsideDown) {
NSLog(@"Portrait");
if ([orientationObject isEqualToString:@"p"]) {
//If the document is portrait
pdfScrollViewFrame = CGRectMake(-0.0, -80.0, 770.0, 1085.0);
}
else{
// If the document is landscape
pdfScrollViewFrame = CGRectMake(-0.0, -40.0, 770.0, 1130.0);
}
}
else{
NSLog(@"Landscape");
if ([orientationObject isEqualToString:@"p"]) {
//If the document is portrait
pdfScrollViewFrame = CGRectMake(65.0, -80.0, 620.0, 1110.0);
}
else{
//if the document is landscape
pdfScrollViewFrame = CGRectMake(0.0, -40.0, 740.0, 1070.0);
}
}
最佳答案
对于 iOS6+,你可以将它添加到你的 Controller 中:
- (BOOL)shouldAutorotate {
YES;
}
- (NSUInteger)supportedInterfaceOrientations {
if (<PDF is portrait>)
return UIInterfaceOrientationMaskPortrait;
if (<PDF is landscape>)
return UIInterfaceOrientationMaskLandscape;
return UIInterfaceOrientationMaskAll;
}
希望这对您有所帮助。
编辑:
我不确定您是否需要手动旋转 PDF 以获得您想要的结果。在这种情况下,您可以尝试使用类似的方法:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toOrientation
duration:(NSTimeInterval)duration {
if (toOrientation == UIInterfaceOrientationMaskLandscape)
pdfScrollViewFrame.transform = CGAffineTransformMakeRotation(M_PI/2);
… // handle all other cases here
}
为了仅在 viewDidAppear
之后锁定旋转,我将执行以下操作:
@interface…
…
@property (nonatomic) BOOL isRotationLocked;
…
@end
@implementation…
…
- (void)viewDidAppear:(BOOL)animated {
…
self.isRotationLocked = YES;
}
- (BOOL)shouldAutorotate {
YES;
}
- (NSUInteger)supportedInterfaceOrientations {
if (self.isRotationLocked) {
if (<PDF is portrait>)
return UIInterfaceOrientationMaskPortrait;
if (<PDF is landscape>)
return UIInterfaceOrientationMaskLandscape;
}
return UIInterfaceOrientationMaskAll;
}
…
关于ios - 如何在 iPhone 中以纵向/横向锁定屏幕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20603996/
我是一名优秀的程序员,十分优秀!