我是iphone开发的新手.在我的应用程序中,我想在设备中显示带有c纵向Orientation的Web视图.它还应该支持横向.我使用了下面的方法,但没有预期的输出.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait ||
interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation ==
UIInterfaceOrientationLandscapeRight);
}
Run Code Online (Sandbox Code Playgroud)
请指导我.请帮帮我.谢谢
我正在使用以下嵌入代码在IOS上嵌入我的YouTube视频
- (NSString*)embedYouTube:(NSString*)youtube_id frame:(CGRect)frame {
NSString* embedHTML = @"\
<html><head>\
<style type=\"text/css\">\
body {\
background-color: transparent;\
color: white;\
}\
</style>\
</head><body style=\"margin:0\">\
<iframe src=\"http://www.youtube.com/embed/%@?rel=0\" frameborder=\"0\" allowfullscreen width=\"%0.0f\" height=\"%0.0f\"></iframe>\
</body></html>";
NSString *html = [NSString stringWithFormat:embedHTML, youtube_id, frame.size.width, frame.size.height];
return html;
}
//code to embed video
NSString *contentHTML;
if (currentAnswer.youtube_id != nil) {
contentHTML = [self embedYouTube:currentAnswer.youtube_id frame:CGRectMake(CELL_TEXT_LEFT_MARGIN + CELL_AVATAR_WIDTH + CELL_SPACING, currentYAxisValue, CELL_YOUTUBEVIEW_WIDTH, CELL_YOUTUBEVIEW_HEIGHT)];
}
[webView loadHTMLString: contentHTML baseURL:nil];
Run Code Online (Sandbox Code Playgroud)
当我播放视频时,它只播放在potrait模式而不是横向模式.这是由于'iframes'的限制吗,有什么方法可以解决这个问题吗?
任何人都可以详细解释为什么iOS在框架和转换方面处理它的横向方向吗?
我所说的是通过在各种View Lifecycle方法中记录视图描述来显示以下行为:
viewDidLoad: "UIView: 0x1edb5ba0; frame = (0 0; 568 320); autoresize = W+H; layer = <CALayer: 0x1edb5c50>"
viewWillAppear: "UIView: 0x1edb5ba0; frame = (0 0; 320 568); autoresize = W+H; layer = <CALayer: 0x1edb5c50>"
viewDidAppear: "UIView: 0x1edb5ba0; frame = (0 0; 320 568); transform = [0, 1, -1, 0, 0, 0]; autoresize = W+H; layer = <CALayer: 0x1edb5c50>"
Run Code Online (Sandbox Code Playgroud)
这种影响是微妙的,但非常有趣.
例如,我使用Initial Interface Orientation启动我的应用程序,并将Supported Interface Orientations设置为"Landscape(右主页按钮)"
然后我显示我的rootViewController,如下所示:
self.viewController = [[MyViewController alloc] initWithNibName:nil bundle:nil];
self.window.rootViewController = self.viewController;
Run Code Online (Sandbox Code Playgroud)
这个.xib的方向设置为Landscape,它的框架设置为0,0,568,320.它显示正确,我可以触摸屏幕上的所有点.
当我提出这样的子视图时,问题就出现了:
SomeView *someView = …Run Code Online (Sandbox Code Playgroud) 我在我的针对iOS的混合移动应用程序中使用Cordova启动画面插件(https://github.com/apache/cordova-plugin-splashscreen).我将所有启动画面图像添加到我的项目中,如下所示:

使用此插件的原因是为了延长启动画面的显示时间,我稍后会在应用程序中手动隐藏它.所以我的config.xml有以下声明:
<preference name="AutoHideSplashScreen" value="false" />
<preference name="ShowSplashScreenSpinner" value="false"/>
Run Code Online (Sandbox Code Playgroud)
此插件在iPhone和iPad上的纵向模式下工作正常.但在横向模式的iPad上,该插件以纵向模式显示启动图像,因此即使设备处于横向模式,我的第一个应用程序视图也会以纵向模式显示.下面的屏幕截图显示了当iPad处于横向模式时,启动画面和它下面的黑色空白部分.

有关如何解决此问题的任何建议?
对于某些要求,我的活动需要两种不同的xml布局:
不幸的是Android不容许景观反向创建单独的布局(如我们可以为纵向和横向与做layout-land和layout-port).
AFAIK,唯一的方法是从java代码更改activity-xml.
1)覆盖onConfigurationChanged()方法来检测方向变化,但我无法弄清楚它是横向还是横向反转:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Log.d("TEST","Landscape");
}
}
Run Code Online (Sandbox Code Playgroud)
(android:configChanges="keyboardHidden|orientation|screenSize|layoutDirection"在清单中我的活动标签中的whith)
2)使用此答案中建议的OrientationEventListenerwith SENSOR_DELAY_NORMAL,但在进入我的块之前设备方向会发生变化,因此我得到了视图的延迟更新:if
mOrientationEventListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL){
@Override
public void onOrientationChanged(int orientation) {
if (orientation==0){
Log.e("TEST", "orientation-Portrait = "+orientation);
} else if (orientation==90){
Log.e("TEST", "orientation-Landscape = "+orientation);
} else if(orientation==180){
Log.e("TEST", "orientation-Portrait-rev = "+orientation);
}else if (orientation==270){
Log.e("TEST", …Run Code Online (Sandbox Code Playgroud) android landscape orientation device-orientation orientation-changes
我已经让接近传感器正常工作,这样我就可以在接近时触发事件,但我试图将其用作一种紧急开关。问题是,每当接近时,屏幕就会关闭,这大大降低了应用程序的可用性:P此外,在横向模式下,接近传感器似乎不会激活(我看不到相机中的闪烁灯) )。有什么办法可以绕过这些标准事件和方法吗?
我正在使用带有UITableViewCell的UITableView.我的应用程序支持横向,所以我创建了2个UITableViewCell:一个用于portraid,另一个用于横向.
在我的cellForRowAtIndexPath方法中,这是我的代码
static NSString *CellIdentifier;
static NSString *NibNamed;
UIDeviceOrientation deviceOrientation = [UIApplication sharedApplication].statusBarOrientation;
if (deviceOrientation != UIDeviceOrientationLandscapeLeft &&
deviceOrientation != UIDeviceOrientationLandscapeRight)
{
CellIdentifier= @"Cell1";
NibNamed = @"cell_news";
}
else
{
CellIdentifier= @"Cell2";
NibNamed = @"cell_news_landscape";
}
[[NSBundle mainBundle] loadNibNamed:NibNamed owner:self options:NULL];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:NibNamed owner:self options:nil];
cell = [nib objectAtIndex:0];
}
///here i add title, description, ecc... in my UITableViewCell
Run Code Online (Sandbox Code Playgroud)
然后在shouldAutorotateToInterfaceOrientation我写了这个:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
[my_table reloadData];
return …Run Code Online (Sandbox Code Playgroud) 我一直在制作一款iOS应用程序,直到现在我才在iPad上进行测试,而我现在正努力让它在iPhone和iPod上运行.
我的应用程序只是横向,我在我的项目文件中设置了允许的方向,只允许在iPad和iPhone上使用横向.这在iPad上运行得很好......飞溅在风景中出现,它可以很好地应用到应用程序中.在我的iPod上,它不是那么好用.我已将所有正确的肖像图像放入Xcode中,但当它加载时(在模拟器上和我的iPod上),它会将图像旋转到装载的一半.因此,它以纵向方向开始我的肖像图像,然后在几秒钟后,它突然将图像旋转90度并将其拉伸至仍然适合屏幕.然后继续加载横向应用程序.无论我尝试什么,它都会继续这样做......任何人都可以对这种情况有所了解吗?我想要它做的是加载启动图像,然后淡入应用程序.
图像显示发生了什么:
http://jamesmcilveen.com/images/1.jpg http://jamesmcilveen.com/images/2.jpg
我已经尝试在所有不同的viewControllers中设置shouldAutorotateToInterfaceOrientation只返回yes,如果支持方向和类似的东西,但它仍然不起作用..
我甚至在新安装的Cordova中重新启动了我的项目,我仍然遇到了同样的问题.在使用默认的Cordova启动图像进行新的未更改安装时,我甚至遇到了问题.
我用谷歌搜索了几个小时,并且惊讶于没有其他人遇到过和我一样的问题?
哦,我顺便使用Cordova 2.7.0,忘记提及.
我基本上是在回答这个问题AVCaptureVideoPreviewLayer方向 -除了在Swift中需要景观.
我的目标是iOS 8,而AVCaptureVideoPreviewLayer似乎没有setVideoOrientation功能.
我应该如何检测方向已更改,并正确旋转AVCaptureVideoPreviewLayer?
我想以横向模式在Flutter应用程序中显示单个页面。其他所有屏幕均应以纵向模式显示。
我找到了以下代码片段:
在我的main.dart中
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]).then((_) {
runApp(new IHGApp());
});
Run Code Online (Sandbox Code Playgroud)
这将以纵向模式启动该应用程序。所以我有要在横向模式下显示的屏幕,这是我在那里使用的代码:
@override
void initState() {
super.initState();
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft,
]);
}
@override
void dispose() {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
super.dispose();
}
Run Code Online (Sandbox Code Playgroud)
这适用于Android。
在iOS上,似乎无法对单个页面强制使用横向模式。
https://github.com/flutter/flutter/issues/13238
在本文中,我找到了此问题的问题。鲁rod的提到了如何解决这个问题。
“我解决了创建一个小型平台通道的问题,该通道调用此代码以在调用setPreferredOrientations之前立即切换到肖像:”
[[UIDevice currentDevice] setValue:@(UIInterfaceOrientationPortrait) forKey:@"orientation"];
Run Code Online (Sandbox Code Playgroud)
和对应的代码切换到风景
[[UIDevice currentDevice] setValue:@(UIInterfaceOrientationLandscapeLeft) forKey:@"orientation"];
Run Code Online (Sandbox Code Playgroud)
如何在我的应用程序中实现呢?