我正在尝试为我的应用程序强制"纵向"模式,因为我的应用程序绝对不是为"横向"模式设计的.
在阅读了一些论坛后,我在清单文件中添加了这些行:
<application
android:debuggable="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:screenOrientation="portrait">
Run Code Online (Sandbox Code Playgroud)
但它不适用于我的设备(HTC Desire).它从"纵向"lo"横向"切换,忽略清单文件中的行.
在更多论坛阅读之后,我尝试在我的清单文件中添加它:
<application
android:debuggable="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:configChanges="orientation"
android:screenOrientation="portrait">
Run Code Online (Sandbox Code Playgroud)
这个函数在我的activity类中:
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
Run Code Online (Sandbox Code Playgroud)
但同样,没有运气.
我已经看到了能够为一个活动指定两个单独的布局xml文件的引用,一个用于Portrait,一个用于Landscape.我没有找到任何有关如何做到这一点的信息.如何为每个活动指定哪个xml文件是纵向布局,哪个是横向布局?
是否也可以为不同的屏幕尺寸指定不同的布局?如果是这样,这是怎么做到的?
注意:这个问题来自2008年,现在只具有历史意义.
无论设备的位置如何,创建从横向模式运行的iPhone应用程序的最佳方法是什么?
以编程方式和使用Interface Builder.
我的应用程序(iPad; iOS 6)是一个仅限风景的应用程序,但是当我尝试使用UIPopoverController来显示照片库时,它会抛出此错误:
Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES.
我尝试更改了很多代码,但我没有运气.
请告诉我出错的地方.
我正在创建一个应用程序,其活动之一仅在横向模式下.所以我在AndroidManifest.xml文件中添加了以下内容
<activity android:name=".LandScapeImageActivity" android:screenOrientation="landscape"></activity>
Run Code Online (Sandbox Code Playgroud)
我创建了一个像这样的文件夹
/ RES /布局,土地
并在其中添加名为see_today_landscape_layout的布局.
在onCreate()
我添加以下内容
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.see_today_landscape_layout);
....
}
Run Code Online (Sandbox Code Playgroud)
但是,当我运行我的应用程序时,我收到以下错误
02-06 13:46:14.358: E/AndroidRuntime(13286): FATAL EXCEPTION: main
02-06 13:46:14.358: E/AndroidRuntime(13286): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mid.kew.activities/com.mid.kew.activities.LandScapeImageActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f03002b
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2787)
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2803)
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4066)
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.app.ActivityThread.access$2400(ActivityThread.java:135)
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2140)
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.os.Handler.dispatchMessage(Handler.java:99)
02-06 13:46:14.358: E/AndroidRuntime(13286): at android.os.Looper.loop(Looper.java:144)
02-06 …
Run Code Online (Sandbox Code Playgroud) 我试图在我的应用程序中强制只有一个视图在横向模式,我打电话
override func shouldAutorotate() -> Bool {
print("shouldAutorotate")
return false
}
override func supportedInterfaceOrientations() -> Int {
print("supportedInterfaceOrientations")
return Int(UIInterfaceOrientationMask.LandscapeLeft.rawValue)
}
override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
return UIInterfaceOrientation.LandscapeLeft
}
Run Code Online (Sandbox Code Playgroud)
视图以纵向模式启动,并在更改设备方向时保持旋转.
永远不会调用shouldAutorotate.
任何帮助,将不胜感激.
无论如何都要确定设备是默认的纵向还是横向?我的意思是你通常如何使用该设备.
大多数手机都有正常使用的人像屏幕,但有一些标志可以找到它吗?
我的应用程序仅通过supportedInterfaceOrientation
属性支持横向方向.
使用iOS 6之前的iOS,我的应用程序可以成功加载UIImagePickerController
via 的实例,presentViewController:animated:completion:
即使它UIImagePickerController
本身只支持纵向方向.
图像选择器简单地向用户侧面呈现.用户旋转手机,拾取他们的图像,然后旋转回横向.
在iOS 6.0下,presentViewController:animated:completion:
使用UIImagePickerController
实例调用会使应用程序崩溃.我可以通过向我的supportedInterfaceOrientation
属性添加纵向选项来防止崩溃.
但是,纵向操作对我的应用来说真的没有用.我原本以为我可以使用shouldAutorotateToInterfaceOrientation
该应用程序"支持肖像",但只允许在这一个视图中旋转到肖像.但是现在该方法已被弃用,我不能在shouldAutorotate中使用相同的技术.
有没有人有任何想法如何在iOS 6.0下解决这个问题?
当我在landscape
模式下启动我的ViewController时(在调用viewDidLoad之后),我打印框架,它给了我纵向模式的帧大小.
这是一个bug有什么建议吗?
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"%@", NSStringFromCGRect(self.view.frame));
// Result is (0, 0 , 768, 1024)
}
Run Code Online (Sandbox Code Playgroud)