是这样的 我只想专门做一个可以横屏播放视频的controller 有人知道怎么弄吗 我已经写好代码 只有横屏没实现了 如果可以 你可以运行一下我的代码 我把.h .m发给你,实现横屏 不要说把project里面的landspace 勾选 我只想用代码控制横屏 谢谢
PHP中文网2017-04-17 17:36:58
這個問題和 https://segmentfault.com/q/1010000004486783/a-1020000004487227 挺像。我把我的回答搬過來了:
在 ViewController 中加入 shouldAutorotate
方法,裡面的邏輯大致如下:
@implementation ViewController
- (BOOL)shouldAutorotate {
int32_t i = 1;
if (i == 1) {
return NO;
}
return YES;
}
@end
如果你的 ViewController 是管理在 UINavigationController 中,則需要去修改 UINavigationController 對應的行為,例如透過 Category 的方式實現想法大致如下:
#import "UINavigationController.h"
@implementation UINavigationController (Overrides)
- (BOOL)shouldAutorotate {
id currentViewController = self.topViewController;
if ([currentViewController isKindOfClass:[<#your-vc#> class]]) {
int32_t i = 1;
if (i == 1) {
return NO;
}
return YES;
}
return YES;
}
@end