ios - iOS,UIScrollView 中的第一页启用横向,第二页禁用横向
问题描述
有一个 UIScrollView,它有两页,UIScrollView 中的第一页我想启用横向,UIScrollView 中的第二页我想禁用横向,现在我使用下面的代码,但它不起作用完善后,第二页先横屏再竖屏:
- (void)viewWillAppear:(BOOL)animated {
[ITNotificationCenter addObserver:self selector:@selector(handleDeviceOrientationDidChange) name:UIDeviceOrientationDidChangeNotification object:nil];
}
- (void)handleDeviceOrientationDidChange{
if(isFirstPage){
//landscape code
} else {
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
}
}
我怎样才能做到这一点?每一个答案将不胜感激。
解决方案
问题已解决。只需看下面的代码。
AppDelegate.h 文件:
@property (nonatomaic, assign, getter=isNeedRotation) BOOL needRotation;
AppDelegate.m 文件:
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if (self.isNeedRotation) {
return UIInterfaceOrientationMaskPortrait;
}
return UIInterfaceOrientationMaskAllButUpsideDown;
}
你的 UIViewController.m 文件:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView == self.mainScrollView) {
AppDelegate *appDelegate = (AppDelegate *)ITUIApplicationDelegate;
if (scrollView.contentOffset.x < screen_width) {
appDelegate.needRotation = YES;
} else {
appDelegate.needRotation = NO;
}
}
}
推荐阅读
- typo3 - TYPO3 TCA 和选择表格
- python - 我无法捕捉到 sys.exit()
- sdk - OTT 解决方案如何将他们的应用程序插入 ISP 机顶盒
- python - Python:通过 Selenium remotedriver 手动配置 Chrome://settings
- python - 对多个字符串变量应用相同的格式
- apache-kafka - kafka 连接到 Google BigQuery 引发错误 Kafka Connect 架构必须是“结构”类型
- excel - VBA Excel在出现空白行后选择内容
- .net - DbFunctions or similar to compare time of day of a datetime type column in Linq to Entity Framework
- angular - 角材料:禁用时不改变颜色(仅添加不透明度)
- database - 连续数据流的数据库设计