- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
更新 2
在我的 UITabBarController 子类中,我尝试添加这个:
-(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
}
现在,每次我选择一个选项卡项时,设备都会完美地旋转到纵向模式。但是,现在我可以在选择 (a) 时旋转设备,设备将旋转到横向模式。如何停止设备旋转?
我相信我的选项卡 Controller 子类中的这个方法是造成这种情况的原因:
- (BOOL)shouldAutorotate {
if(self.selectedIndex == 0)
{
return NO;
}
return [self.viewControllers.lastObject shouldAutorotate];
}
如果我返回“NO”,当我在 View Controller 中时我不能旋转,但是当我选择它时,它不会自动旋转到纵向。如果我返回"is",我可以在 View Controller 中旋转,但当我选择它时,它会自动旋转为纵向。
我的应用程序中有一个自定义标签栏 Controller ,具有以下层次结构:
UITabBarController
|
UINavigationController
| |
| UIViewController(a)
|
UINavigationController
| |
| UIViewController(b)
|
UINavigationController
|
UIViewController(c)
我希望 View Controller (a) 只能在纵向模式下查看,而 View Controller (b) 和 (c) 可以在所有方向上查看,但要倒置。现在,我可以单独对每个 View Controller 执行此操作,但是当我处于 (b) 横向模式时,我的问题就出现了,并选择 (a) 的选项卡项,然后 a 以横向模式显示,看起来不好的。如何确保选项卡栏(或 View Controller )检查是否可以在当前方向查看要选择的 View Controller ?
如果需要,这是我的 (a) 代码,它自己将其限制为纵向模式:
- (BOOL) shouldAutorotate
{
return NO;
}
- (NSUInteger) supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
更新
我已将此添加到 View Controller (a),但我的 View 中间出现了一个黑色方 block ,并且导航栏中的标题不再居中。
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
}
最佳答案
自 iOS 7.0 UITabBarController 支持通过 - (NSUInteger)tabBarControllerSupportedInterfaceOrientations:(UITabBarController *)tabBarController
进行定向转发。
在您处于此特定选项卡不支持的界面方向时切换到另一个选项卡之前,它会很好用。
不幸的是,在这种情况下,tabbar Controller 不会强制旋转,唯一的方法是使用私有(private) API。
注意:当从仅纵向选项卡切换回支持任何方向的选项卡时,我使用 attemptRotationToDeviceOrientation
将界面旋转到设备方向。
这是我解决问题的方法:
static const NSInteger kPortraitOnlyTabIndex = 1;
@interface TabBarController : UITabBarController<UITabBarControllerDelegate>
@end
@implementation TabBarController
- (id)initWithCoder:(NSCoder *)aDecoder {
if(self = [super initWithCoder:aDecoder]) {
self.delegate = self;
}
return self;
}
- (NSUInteger)tabBarControllerSupportedInterfaceOrientations:(UITabBarController *)tabBarController {
if(tabBarController.selectedIndex == kPortraitOnlyTabIndex) {
return UIInterfaceOrientationMaskPortrait;
}
return UIInterfaceOrientationMaskAllButUpsideDown;
}
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
[UIViewController attemptRotationToDeviceOrientation];
if([self.viewControllers indexOfObject:viewController] == kPortraitOnlyTabIndex) {
SEL sel = NSSelectorFromString(@"setOrientation:");
if([[UIDevice currentDevice] respondsToSelector:sel]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[[UIDevice currentDevice] performSelector:sel withObject:(__bridge id)((void*)UIInterfaceOrientationPortrait)];
#pragma clang diagnostic pop
}
}
}
@end
我将示例应用程序放在 Github 上 https://github.com/pronebird/TabBarOrientationExample
关于ios - 限制选项卡栏 View Controller 中的旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27141594/
我有一个 ServiceBusQueue(SBQ),它获取大量消息负载。我有一个具有 accessRights(manage) 的 ServiceBusTrigger(SBT),它不断轮询来自 SBQ
在下面给出的结果集中,有 2 个唯一用户 (id),并且查询中可能会出现更多此类用户: 这是多连接查询: select id, name, col1Code, col2Code, col2Va
我正在用 Python 2.7.3 编写一个带有 GRequests 的小脚本和 lxml 可以让我从各种网站收集一些收藏卡价格并进行比较。问题是其中一个网站限制了请求的数量,如果我超过它,就会发回
我想知道何时实际使用删除级联或删除限制以及更新级联或更新限制。我对使用它们或在我的数据库中应用感到很困惑。 最佳答案 在外键约束上使用级联运算符是一个热门话题。 理论上,如果您知道删除父对象也将自动删
下面是我的输出,我只想显示那些重复的名字。每个名字都是飞行员,数字是飞行员驾驶的飞机类型。我想显示驾驶不止一架飞机的飞行员的姓名。我正在使用 sql*plus PIL_PILOTNAME
我正在评估不同的移动框架,我认为 nativescript 是一个不错的选择。但我不知道开发过程是否存在限制。例如,我对样式有限制(这并不重要),但我想知道将来我是否可以有限制并且不能使用某些 nat
我正在尝试使用 grails 数据绑定(bind)将一些表单参数映射到我的模型中,但我认为在映射嵌入式集合方面可能存在一些限制。 例如,如果我提交一些这样的参数,那么映射工作正常: //this wo
是否可以将 django 自过滤器起的时间限制为 7 天。如果日期超过 7 天,则不应用过滤器 最佳答案 timesince 的源代码位于 django/django/utils/timesince.
我想在我的网站上嵌入一个 PayPal 捐赠按钮。但问题是我住在伊朗——这个国家受到制裁,人们不使用国际银行账户或主要信用卡。 有什么想法吗?请帮忙! 问候 沮丧 最佳答案 您可以在伊朗境内使用为伊朗
这是我的查询 select PhoneNumber as _data,PhoneType as _type from contact_phonenumbers where ContactID = 3
这个问题在这里已经有了答案: What is the maximum number of parameters passed to $in query in MongoDB? (4 个答案) 关闭
我的一个项目的 AndroidManifest.xml 变得越来越大(> 1000 行),因为我必须对某些文件类型使用react并且涵盖所有情况变得越来越复杂。我想知道 list 大小是否有任何限制。
在使用 Sybase、Infomix、DB2 等其他数据库产品多年后使用 MySQL 5.1 Enterprise 时;我遇到了 MySQL 不会做的事情。例如,它只能为 SELECT 查询生成 EX
这个问题在这里已经有了答案: What is the maximum number of parameters passed to $in query in MongoDB? (4 个回答) 关闭5年
通常我们是在{$apache}/conf/httpd.conf中设置Apache的参数,然而我们并没有发现可以设置日志文件大小的配置指令,通过参考http://httpd.apache.org/do
我正在搜索最大的 Android SharedPreferences 键值对,但找不到任何好的答案。其次,我想问一下,如果我有一个键,它的字符串值限制是多少。多少字符可以放入其中。如果我需要频繁更改值
我目前正在试验 SoundCloud API,并注意到我对/tracks 资源的 GET 请求一次从不返回超过 200 个结果。关于这个的几个问题: 这个限制是故意的吗? 有没有办法增加这个限制? 如
我正在与一家名为 Dwolla 的金融技术公司合作,该公司提供了一个 API,用于将银行信息附加到用户并收取/发送 ACH 付款。 他们需要我将我的 TLS 最低版本升级到 1.2(禁用 TLS 1.
我在 PHP 中有一个多维数组,如下所示: $array = Array ( [0] => Array ( [bill] => 1 ) [1] => Array ( [
我在获取下一个查询的第一行时遇到了问题: Select mar.Title MarketTitle, ololo.NUMBER, ololo.Title from Markets mar JOIN(
我是一名优秀的程序员,十分优秀!