我开发了iOS应用程序并在iOS6设备上进行了测试.在测试时,我意识到我的应用程序没有按预期响应方向更改.
这是我的代码:
// Autorotation (iOS >= 6.0)
- (BOOL) shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)
确切地说,我想知道iOS中的方向更改调用了哪些方法.
嗨,我有一个应用程序,我有两个*.pngs默认闪屏:
Default-Landscape.png Default-Portrait.png
我想要的是在我的应用程序加载并准备好时,将此默认启动画面设置为动画.
为了达到这个目的,我通常会使用默认横向或默认纵向(取决于设备方向)呈现UIImageView,将其保留在屏幕上一段时间,然后将其设置为动画.
我的问题是,如果我呼吁[[UIDevice currentDevice] orientation]在
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
Run Code Online (Sandbox Code Playgroud)
答案始终是设备处于纵向方向,即使我清楚地将其置于风景中.我在模拟器和设备上尝试了这个,行为是一样的.
有没有人知道这个或其他方法的解决方案?
谢谢!
iphone uikit uidevice uiinterfaceorientation device-orientation
我有一个支持方向更改的iPad应用程序的嵌套视图层次结构.它看起来与以下类似.
UIViewController
UIView
- UIView
- UIImageView (disable rotation)
- UIImageView
- UIView (disable rotation)
- UIView
- UIView
...
Run Code Online (Sandbox Code Playgroud)
我想锁定一些子视图的方向,同时允许其他人自动旋转和调整大小.我似乎无法弄清楚如何实现这一目标.
一种方法似乎是手动旋转子视图willAnimateRotationToInterfaceOrientation:.鉴于SDK正在执行我将要撤消的轮换,这并不是特别有吸引力.
有没有办法简单地禁用子视图的方向更改或其他方法来重构我的层次结构?
当我更改设备的方向时,我在使用制表符和片段重新加载活动时遇到问题.
情况如下:
我有一个活动,在操作栏中有3个标签.每个选项卡FrameLayout在主视图中加载不同的片段.如果我不改变设备的方向,一切正常.但是,当我这样做时,Android会尝试将当前选定的片段初始化两次,从而产生以下错误:
E/AndroidRuntime(2022): Caused by: android.view.InflateException: Binary XML file line #39: Error inflating class fragment
Run Code Online (Sandbox Code Playgroud)
以下是产生错误的步骤序列:
Activity.onCreate()我将第一个标签添加到操作栏.当我这样做时,会自动选择此选项卡.它可能代表未来的问题,但我现在不介意.onTabSelected调用并创建并加载第一个片段的新实例(参见下面的代码).ActionBar.selectTab(myTab)选择Tab nr 2.onTabUnselected()调用第一个选项卡,然后调用onTabSelected()第二个选项卡.此序列替换Fragment 2实例的当前片段(请参阅下面的代码).Fragment.onCreateView()在Fragment 2实例上调用,片段布局变得膨胀.onCreate()然后调用onCreateView()片段实例ONCE AGAIN,当我尝试(第二次)对布局进行充气时会产生异常.显然问题是Android正在初始化片段两次,但我不知道为什么.
当我自动加载活动时,我尝试不选择第二个标签,但第二个片段无论如何都被初始化并且没有显示(因为我没有选择它的标签).
我发现了这个问题:Android片段在方向更改时重新创建
用户问我的基本相同,但我不喜欢所选择的答案(它只是一个workaroud).必须有一些方法让这个工作没有android:configChanges诀窍.
如果不清楚,我想知道如何阻止片段的重新创建或避免它的双重初始化.很高兴知道为什么会发生这种情况.:P
这是相关代码:
public class MyActivity extends Activity implements ActionBar.TabListener {
private static final String TAG_FRAGMENT_1 = "frag1";
private static final String TAG_FRAGMENT_2 = …Run Code Online (Sandbox Code Playgroud) API演示 - >图形 - > 指南针
它只能正常工作,直到您不更改设备的自然方向.在大多数手机中,肖像和大多数10英寸平板电脑是风景.如果你改变而不是需要旋转90度.我想看看该系统的3D修复.
100%肯定需要使用remapCoordinateSystem()方法.
我想看看如何(代码)如果我能看到如何计算那些轴映射(理论数学)的解释它会很好.
我试着理解,但我忘记了所有的线性代数.
这里说明为什么我们必须使用,但不告诉如何!
float R[] = new float[9];
// X (product of Y and Z) and roughly points East
// Y: points to Magnetic NORTH and tangential to ground
// Z: points to SKY and perpendicular to ground
float I[] = new float[9];
boolean success = SensorManager.getRotationMatrix(R, I, mGravity, mGeomagnetic);
Run Code Online (Sandbox Code Playgroud)
似乎那些坐标是这个位置: - 设备在表格中说(x,y轴在桌子上)

只有,如果
getWindowManager().getDefaultDisplay().getRotation() == Surface.ROTATION_0
Run Code Online (Sandbox Code Playgroud)
问题是如何完成此代码: - 那些案例分支
switch (mScreenRotation) {
case Surface.ROTATION_0:
Log.v("SurfaceRemap", "0 degree");
axisX …Run Code Online (Sandbox Code Playgroud) 有两种方法可以获得3个旋转值(方位角,俯仰,滚动).
一个是注册TYPE_ORIENTATION类型的监听器.这是最简单的方法,我从每次旋转中得到正确的值范围,如文档所示:azimuth:[0,359] pitch:[ - 180,180] roll:[ - 90,90]
另一个,你第一次看到它时最精确和最复杂.Android推荐它,所以我想使用它,但我得到不同的值.
方位角:[ - 180,180].-180/180是S,0 i N,90 E和-90 W.
pitch:[ - 90,90 ].90为90,-90为-90,0为0但-180/180(屏幕向下)为0.
roll:[ - 180,180].
我应该得到相同的值,但有小数,对吧?
我有以下代码:
aValues = new float[3];
mValues = new float[3];
sensorListener = new SensorEventListener (){
public void onSensorChanged (SensorEvent event){
switch (event.sensor.getType ()){
case Sensor.TYPE_ACCELEROMETER:
aValues = event.values.clone ();
break;
case Sensor.TYPE_MAGNETIC_FIELD:
mValues = event.values.clone ();
break;
}
float[] R = new float[16];
float[] orientationValues = new float[3];
SensorManager.getRotationMatrix (R, null, aValues, mValues);
SensorManager.getOrientation (R, orientationValues);
orientationValues[0] …Run Code Online (Sandbox Code Playgroud) 我一直试图从前置摄像头捕捉帧并将其呈现在视图上.这是我的代码
_session = [[AVCaptureSession alloc] init];
_session.sessionPreset = AVCaptureSessionPreset640x480;
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error = nil;
AVCaptureDeviceInput *deviceInput = [[AVCaptureDeviceInput alloc] initWithDevice:device error:&error];
if (deviceInput) {
[_session addInput:deviceInput];
}
else {
DDLogInfo(@"Some wierd shit happened");
return;
}
// Session output
/*
AVCaptureMetadataOutput *output = [[AVCaptureMetadataOutput alloc] init];
[output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
[_session addOutput:output];
output.metadataObjectTypes = @[AVMetadataObjectTypeFace];
AVCaptureConnection *connection = [output connectionWithMediaType:AVMediaTypeMetadata];
connection.videoOrientation = AVCaptureVideoOrientationLandscapeLeft;
*/
// Session output
AVCaptureMovieFileOutput *videoOutput = [[AVCaptureMovieFileOutput alloc] init];
[_session addOutput:videoOutput];
AVCaptureConnection *connection = …Run Code Online (Sandbox Code Playgroud) 我正在尝试平滑我从deviceOrientation API获取的数据,以便在浏览器中创建Google Cardboard应用程序.
我正在将加速度计数据直接输入到ThreeJs相机旋转中,但是我们在信号上产生了很多噪音,导致视图抖动.
有人建议使用卡尔曼滤波器作为处理平滑信号处理噪声的最佳方法,我在gitHub上找到了这个简单的Javascript库
https://github.com/itamarwe/kalman
然而它在文档上真的很轻松.
我知道我需要通过提供Vector和3矩阵作为参数来创建一个Kalman模型,然后再次使用矢量和矩阵作为时间范围内的参数来更新模型.
我也理解卡尔曼滤波器方程有几个不同的部分:当前估计位置,卡尔曼增益值,来自方向API的当前读数和先前估计的位置.
我可以看到3D空间中的一个点可以被描述为一个Vector,因此任何位置值,例如估计位置或当前读数都可以是Vector.
我不明白的是这些部分如何被翻译成矩阵以形成Javascript库的参数.
我升级到了xCode 4.2,它是新的Storyboard功能.但是,找不到支持肖像和风景的方法.
当然,我是以编程方式完成的,有2个视图,一个用于纵向,一个用于横向,就像过去一样,并且:
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
self.view = self.landscapeView;
}
else
{
self.view = self.portraitView;
}
Run Code Online (Sandbox Code Playgroud)
但我正在寻找一种方法,以某种方式自动执行此操作.我的意思是,现在是xCode 4.2,我期待更多.谢谢大家.
==================================
临时解决方案:
我将在这里提出一个临时解决方案.我说这是暂时的,因为我还在等苹果公司做一些非常聪明的事情.
我创建了另一个.storyboard文件,名为"MainStoryboard_iPhone_Landscape",并在那里实现了横向视图控制器.实际上,它与普通(肖像).storyboard完全一样,但所有屏幕都处于横向模式.
所以我将从横向故事板中提取ViewController,当轮换发生时,只需使用新的viewController视图更改self.view.
1.方向更改时生成通知:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
Run Code Online (Sandbox Code Playgroud)
2.寻找通知:
[[NSNotificationCenter defaultCenter] addObserverForName:UIDeviceOrientationDidChangeNotification object:nil queue:nil usingBlock:^(NSNotification *note) {
// 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];
}];
Run Code Online (Sandbox Code Playgroud)
3.实现updateLandscapeView
- (void)updateLandscapeView {
//> isShowingLandscapeView is declared in AppDelegate, …Run Code Online (Sandbox Code Playgroud) 我正在使用React Native 0.29并为Android开发.我正试图锁定设备方向.我需要的是以纵向模式锁定屏幕.我尝试使用此存储库https://github.com/yamill/react-native-orientation但它尚未支持RN 0.29.
有什么方法可以锁定设备方向吗?也许任何原生的Android黑客与Android工作室?
android ×4
iphone ×3
orientation ×3
ios ×2
ipad ×2
ios6 ×1
ipad-3 ×1
javascript ×1
landscape ×1
react-native ×1
sensor ×1
storyboard ×1
tabs ×1
uidevice ×1
uikit ×1
uiview ×1
xcode4.2 ×1