gpt4 book ai didi

iphone - UIWebView 中横向模式的 Youtube 视频

转载 作者:技术小花猫 更新时间:2023-10-29 10:39:53 26 4
gpt4 key购买 nike

我的申请不是为景观而生的。但是,当我在 UIWebView 中打开我的 YouTube channel 并且用户启动视频 时,它会出现在纵向中。如果用户旋转他的 iPhone,我想让它以横向模式显示。

在这种情况下如何启用横屏模式?

我知道有一些“肮脏的黑客”可以做到这一点,但我更喜欢更干净的东西。此外,我不希望 UIWebView 切换到横向,但视频可以。

最佳答案

我最终使用以下代码调整了我的 View ,使其支持横向模式:

- (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));
}

关于iphone - UIWebView 中横向模式的 Youtube 视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8111207/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com