在iPad上的Mobile Safari中,我在更改设备方向后会遇到一些奇怪的行为.这是我的测试文件:
<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="initial-scale=0.7" />
<style>
#block {
border: 1px solid red;
background-color: yellow;
font-size: 400%;
width: 700px;
height: 500px;
}
</style>
</head>
<body>
<div id="block">Hello world!</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
您可以通过以下URL在Mobile Safari中查看它:
http://fiddle.jshell.net/eterps/jsTqj/show/
当我使用我的iPad纵向移动URL并进行一些滑动手势时,页面不会滚动,这是正确的.
然而,当我将设备旋转到横向模式并进行一些滑动手势时,我在右侧获得了额外的空间,没有明显的原因.
但更奇怪的是,当我重新启动移动safari并且一直处于横向方向时转到URL时,右侧的额外空间不存在.
为什么在方向改变后会出现右边的额外空间?我该如何预防呢?
我正在尝试为Android制作指南针应用程序,正如许多其他人在我之前所做的那样.
但是,我在理解整个旋转矩阵事物应该如何工作时遇到了问题.我已经尝试了前进的方法,并提出了以下代码:
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so …Run Code Online (Sandbox Code Playgroud) 当设备方向从横向变为纵向或反之时,我正在执行一个调用不同活动的应用程序.横向模式的活动是增强现实模式,因此我使用相机向用户显示周围环境.但是,当我尝试回到纵向时,应用程序崩溃并显示以下错误:
08-17 16:05:42.622: ERROR/AndroidRuntime(9769): FATAL EXCEPTION: main
08-17 16:05:42.622: ERROR/AndroidRuntime(9769): java.lang.RuntimeException: set display orientation failed
08-17 16:05:42.622: ERROR/AndroidRuntime(9769): at android.hardware.Camera.setDisplayOrientation(Native Method)
08-17 16:05:42.622: ERROR/AndroidRuntime(9769): at es.ucm.look.ar.Preview.surfaceChanged(Preview.java:102)
08-17 16:05:42.622: ERROR/AndroidRuntime(9769): at android.view.SurfaceView.updateWindow(SurfaceView.java:549)
08-17 16:05:42.622: ERROR/AndroidRuntime(9769): at android.view.SurfaceView.setFrame(SurfaceView.java:294)
08-17 16:05:42.622: ERROR/AndroidRuntime(9769): at android.view.View.layout(View.java:7169)
08-17 16:05:42.622: ERROR/AndroidRuntime(9769): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
08-17 16:05:42.622: ERROR/AndroidRuntime(9769): at android.view.View.layout(View.java:7175)
08-17 16:05:42.622: ERROR/AndroidRuntime(9769): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
08-17 16:05:42.622: ERROR/AndroidRuntime(9769): at android.view.View.layout(View.java:7175)
08-17 16:05:42.622: ERROR/AndroidRuntime(9769): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
08-17 16:05:42.622: ERROR/AndroidRuntime(9769): at android.view.View.layout(View.java:7175)
08-17 16:05:42.622: ERROR/AndroidRuntime(9769): at android.view.ViewRoot.performTraversals(ViewRoot.java:1140)
08-17 16:05:42.622: ERROR/AndroidRuntime(9769): at …Run Code Online (Sandbox Code Playgroud) 我正在开发的iPhone应用程序中有一个奇怪的问题.我希望我的应用程序仅支持纵向模式,但由于某种原因我无法做到(设备和模拟器).
为了仅支持肖像模式我做了如下:
shouldAutorotateToInterfaceOrientation 但正如我所说它不起作用,奇怪的结果是该应用程序支持所有方向(纵向,颠倒,左侧景观,右侧景观).
有任何想法吗?
这是我如何实现的 shouldAutorotateToInterfaceOrientation
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
NSLog(@"Checking orientation %d", interfaceOrientation);
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
Run Code Online (Sandbox Code Playgroud)
我刚刚注意到,当我旋转手机时,我收到以下消息:
"不推荐使用两阶段旋转动画.此应用程序应使用更平滑的单级动画."
这是什么意思?
$(window).bind("orientationchange", function(e){
var ow = (e.orientation=="portrait" ? "?" : "?");
alert("?????? "+ow+" ???");
});
Run Code Online (Sandbox Code Playgroud)
使用上面的代码,我可以确定设备是纵向还是横向模式.但我的问题是,是否有可能确定设备倾斜的景观(横向右侧/横向左侧)的哪一侧,如果设备是倒置的?
谢谢你们的支持.
我有一个表格,里面有一个来自plist文件的大量列表,点击每个文件会带你到一个新的视图,一个xib.
我在.xib中有2个视图,一个用于纵向,一个用于横向
在我的文件中我有这个:
IBOutlet UIView *portraitView;
IBOutlet UIView *landscapeView;
@property (nonatomic, retain) IBOutlet UIView *portraitView;
@property (nonatomic, retain) IBOutlet UIView *landscapeView;
Run Code Online (Sandbox Code Playgroud)
在我的m文件中:
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
}
- (void) orientationChanged:(id)object
{
UIInterfaceOrientation interfaceOrientation = [[object object] orientation];
if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
self.view = self.portraitView;
}
else
{
self.view = self.landscapeView;
}
}
- (void)viewDidUnload
{
[super …Run Code Online (Sandbox Code Playgroud) 我在android中的方向有问题.设备方向是我在AndroidManifest.xml文件中设置的横向.
android:screenOrientation="landscape"
Run Code Online (Sandbox Code Playgroud)
此外,我在横向上持有设备,所以一切(布局,视图等)都是横向模式,正如我想要的那样.但只有当我以纵向方式握住设备时,它才能为我提供所需的价值.
我修改了一些来自互联网的代码,它适用于HTC 3d EVO,Nexus 7和三星Galaxy S3,但不适用于Galaxy Tablet 10".
我找到了这篇文章. Android方向传感器对于不同设备有何不同? 接受的答案建议使用getRotation()和remapCoordinateSystem()方法,但不提及如何使用.
这就是我的结局.
SensorManager.getRotationMatrix(Rmat, Imat, gData, mData);
SensorManager.remapCoordinateSystem(Rmat, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, R2);
// Orientation isn't as useful as a rotation matrix, but
// we'll show it here anyway.
SensorManager.getOrientation(R2, orientation);
float incl = SensorManager.getInclination(Imat);
FontTextView pitchText = (FontTextView)findViewById(R.id.pitch_text);
if((int)(orientation[1]*90) <= -110 && !newQuestionIsActive) {
newQuestionIsActive = true;
pitchText.setText("Bring new question");
}
else if(Math.abs((int)(orientation[2]*90)) <= 200 && (int)(orientation[1]*90) >= -30 && newQuestionIsActive) {
newQuestionIsActive = false;
pitchText.setText("Not Correct!");
}
else if(Math.abs((int)(orientation[2]*90)) …Run Code Online (Sandbox Code Playgroud) 我有一个SpriteKit游戏,我想支持所有方向.现在当我改变方向时,节点不会保持其位置.我使用SKSceneScaleModeResizeFill缩放,因为它将保持正确的精灵大小.
当我开始游戏时,游戏玩家就像这样定位在中间屏幕:

然后当我旋转设备时,位置变为如下:

这是我的视图控制器代码:
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
// Configure the view.
SKView * skView = (SKView *)self.view;
if (!skView.scene) {
// Create and configure the scene.
SKScene * scene = [MyScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeResizeFill;
// Present the scene.
[skView presentScene:scene];
}
}
Run Code Online (Sandbox Code Playgroud)
我的场景代码:
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
self.backgroundColor = [SKColor colorWithRed:0.15 green:0.15 blue:0.3 alpha:1.0];
//Add spaceship in the center of the view
SKSpriteNode *spaceship = [SKSpriteNode spriteNodeWithImageNamed:@"Spaceship.png"];
spaceship.position = CGPointMake(size.width/2, size.height/2); …Run Code Online (Sandbox Code Playgroud) 我正在尝试将我的应用的初始方向设置为UIInterfaceOrientationLandscapeLeft
我不能
'Initial interface orientation'[UIInterfaceOrientation]
Run Code Online (Sandbox Code Playgroud)
覆盖数组中的第一项
'Supported interface orientations'[UISupportedInterfaceOrientations]
Run Code Online (Sandbox Code Playgroud)
我注意到一个iphone应用总是以'Portrait(底部主页按钮)'开头.数组是:
'Supported interface orientations'[UISupportedInterfaceOrientations]
Portrait (bottom home button)
Landscape (left home button)
Landscape (right home button)
Run Code Online (Sandbox Code Playgroud)
这是预期的.
如果我在摘要页面上关闭PORTRAIT HOME BOTTOM按钮OFF THEN BACK ON然后数组的顺序改变而Portrait(底部主页按钮)移动到底部.
Landscape (left home button)
Landscape (right home button)
Portrait (bottom home button)
Run Code Online (Sandbox Code Playgroud)
当我运行应用程序时,它现在从横向(左主页按钮)开始,因为它现在是列表的顶部.哪个好
但
当我添加
'Initial interface orientation'[UIInterfaceOrientation]
Run Code Online (Sandbox Code Playgroud)
并将其设置为
Landscape (right home button)
Run Code Online (Sandbox Code Playgroud)
它被忽略,而数组中的第一项则被使用
Landscape (left home button)
Run Code Online (Sandbox Code Playgroud)
我检查了shouldAutorotateToInterfaceOrientation,它只阻止了肖像颠倒
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != …Run Code Online (Sandbox Code Playgroud) 我有一个应用程序,我正在使用Landscape和potrait模式.我在我的每个活动中都使用了android:configChanges ="orientation | keyboardHidden".因此,当我在设备2.3上运行它时,它完全正常工作并且活动没有重新启动.但是当我在android 4.0及更高版本中打开相同的应用程序时,只要方向发生变化,活动就会重新启动.这是我的xml文件.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.iconnect.collaborator"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<supports-screens android:largeScreens="true"
android:normalScreens="true" android:smallScreens="true"
android:anyDensity="true" />
<supports-screens android:smallScreens="true" />
<supports-screens android:normalScreens="true" />
<supports-screens android:largeScreens="true" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:icon="@drawable/cnlogomini"
android:label="CollaborateNow"
android:largeHeap="true"
android:allowBackup="true"
android:theme="@style/AppTheme" >
<activity android:name="jim.h.common.android.zxinglib.CaptureActivity"
android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden" />
<activity android:name=".Register"
android:configChanges="orientation|keyboardHidden" ></activity>
<activity android:name=".ppllogincopy"
android:configChanges="orientation|keyboardHidden"></activity>
<activity android:name=".Password" …Run Code Online (Sandbox Code Playgroud) android orientation screen-orientation device-orientation android-orientation
android ×4
orientation ×3
ios ×2
iphone ×2
autorotate ×1
html5 ×1
ios6 ×1
objective-c ×1
sensor ×1
sprite-kit ×1
viewport ×1
xcode ×1
xcode4.5 ×1