在UIWebView中的横向模式的Youtubevideo
我的应用程序不是为了风景。 但是,当我在UIWebView中打开我的YouTube频道并且用户启动video时 ,它将显示在肖像中。 如果用户旋转他的iPhone,我想使其以横向模式出现。
如何在这种情况下启用横向模式?
我知道有这样的“肮脏的黑客”,但我更喜欢更清洁的东西。 另外我不希望UIWebView切换到风景,但只是video可以。
我最终调整了我的视图,以便它支持横向模式使用下面的代码:
- (void)viewDidLoad { [super viewDidLoad]; [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil]; } - (void)viewWillAppear:(BOOL)animated { UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation; if (UIDeviceOrientationIsLandscape(deviceOrientation)) { //I set my new frame origin and size here for this orientation isShowingLandscapeView = YES; } else if (deviceOrientation == UIDeviceOrientationPortrait) { //I set my new frame origin and size here for this orientation isShowingLandscapeView = NO; } } - (void)orientationChanged:(NSNotification *)notification { // We must add a delay here, otherwise we'll swap in the new view // too quickly and we'll get an animation glitch [self performSelector:@selector(updateLandscapeView) withObject:nil afterDelay:0]; } - (void)updateLandscapeView { UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation; if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView) { //I set my new frame origin and size here for this orientation isShowingLandscapeView = YES; } else if (deviceOrientation == UIDeviceOrientationPortrait && isShowingLandscapeView) { //I set my new frame origin and size here for this orientation isShowingLandscapeView = NO; } } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait || UIInterfaceOrientationIsLandscape(interfaceOrientation)); }
要在横向视图中显示video,只需转到在Xcode中实现了webView的视图的属性检查器,然后将方向从纵向更改为横向。 尽可能简单
不要忘记添加这个代码
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) { return YES; } }
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { id presentedViewController = [window.rootViewController presentedViewController]; NSString *className = presentedViewController ? NSStringFromClass([presentedViewController class]) : nil; if (window && [className isEqualToString:@"AVFullScreenViewController"] && [presentedViewController isBeingDismissed] == NO) { return UIInterfaceOrientationMaskAll; } else { return UIInterfaceOrientationMaskPortrait; }}
//这适用于ios8
- 错误域= NSCocoaErrorDomain代码= 3840“没有值。”UserInfo = {NSDebugDescription =没有值。}
- 滚动时UITableViewCell图像发生变化
- Swift – 有一个audio重复,但它会间隔?
- 如何在Swift 3中正确设置MPNowPlayingInfoCenter
- 如何在本地保存PDF或其他文件在iOS中
- 更新到Xcode 8后的错误:“没有这样的模块”和“目标覆盖EMBEDDED_CONTENT_CONTAINS_SWIFT”build立设置“
- 适用于iOS模拟器,但不适用于iPhone
- 使用自定义起点接收有限查询
- moveRowAtIndexPath没有删除button