标签: landscape-portrait

在iOS 8中处理方向更改的"正确"方法是什么?

有人可以告诉我在iOS 8中使用纵向和横向界面方向的"正确"或"最佳"方法吗?似乎我想要用于此目的的所有功能都在iOS 8中被弃用,而我的研究似乎没有明确,优雅的替代方案.我真的应该看看宽度和高度,以确定我们是在纵向还是横向模式?

例如,在我的视图控制器中,我应该如何实现以下伪代码?

if we are rotating from portrait to landscape then
  do portrait things
else if we are rotating from landscape to portrait then
  do landscape things
Run Code Online (Sandbox Code Playgroud)

orientation uiinterfaceorientation ios landscape-portrait ios8

100
推荐指数
3
解决办法
7万
查看次数

在Android上的纵向模式中的Zxing相机

我想portraitZxing相机上显示方向.

如何才能做到这一点?

android zxing landscape-portrait

40
推荐指数
3
解决办法
4万
查看次数

iOS:保存为PNG表示数据后,图像旋转90度

我已经研究了足够的工作,但无法修复它.只要我将图像存储为UIImage,从相机拍照后,它就可以了,但只要我将此图像存储为PNG表示,它就会旋转90度.

以下是我的代码和我尝试过的所有事情:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{
    NSString *mediaType = [info valueForKey:UIImagePickerControllerMediaType];

    if([mediaType isEqualToString:(NSString*)kUTTypeImage]) 
    {
        AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
        delegate.originalPhoto  = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
        NSLog(@"Saving photo");
        [self saveImage];
        NSLog(@"Fixing orientation");
        delegate.fixOrientationPhoto  = [self fixOrientation:[UIImage imageWithContentsOfFile:[delegate filePath:imageName]]];      
        NSLog(@"Scaling photo");
        delegate.scaledAndRotatedPhoto  =  [self scaleAndRotateImage:[UIImage imageWithContentsOfFile:[delegate filePath:imageName]]];
    }
    [picker dismissModalViewControllerAnimated:YES];
    [picker release];
}


- (void)saveImage
{
    AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    NSData *imageData = UIImagePNGRepresentation(delegate.originalPhoto);
    [imageData writeToFile:[delegate filePath:imageName] atomically:YES];
}
Run Code Online (Sandbox Code Playgroud)

这里分别从这里这里取得fixOrientation和scaleAndRotateImage函数.当我在UIImage上应用它们时,它们工作正常并旋转图像,但如果我将图像保存为PNG表示并应用它们则不起作用.

请执行以上功能后请参考以下图片:

第一张照片是原始的,第二张是保存的,第三张和第四张是在保存的图像上应用fixorientation和scaleandrotate功能后

iphone image-rotation uiimage landscape-portrait ios5.1

38
推荐指数
4
解决办法
4万
查看次数

使用UITabBar在iOS 6中自动旋转单个UIViewController

我有一个只能使用的应用程序Portrait Mode,但是有一个可以显示视频的单一视图,所以我希望该视图也可以工作landscape mode,但是在iOS 6中我无法弄清楚我是如何做到的,现在我有了这个:

在AppDelegate.mi中有:

self.window.rootViewController = myTabBar;
Run Code Online (Sandbox Code Playgroud)

然后在项目摘要中:

在此输入图像描述

我发现在iOS 6中检测视图旋转我必须这样做:

- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}

// Tell the system It should autorotate
- (BOOL) shouldAutorotate {
return YES;
}
Run Code Online (Sandbox Code Playgroud)

所以我只在我的插入代码UIViewController我想在景观中使用,但不工作,谁知道我怎么能这样做?我只是想在显示视频时自动旋转.

iphone uiviewcontroller landscape-portrait ios6

25
推荐指数
1
解决办法
3万
查看次数

子视图控制器旋转而父视图控制器不旋转

我想做什么:

由父视图控制器管理的父视图不应该旋转.

由子视图控制器管理的子视图应该旋转到所有方向.


在此输入图像描述

在此输入图像描述


我试过的:

ParentViewController

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    return .Portrait
}

override func shouldAutorotate() -> Bool {
    return true
}

fun addChildViewController() {
    let storyBoard = UIStoryboard(name: "Main", bundle: nil)
    self.childViewController = storyBoard("Child View Controller") as? ChildViewController
    self .addChildViewController(self.childViewController!)
    self.childViewController! .didMoveToParentViewController(self)
    self.view .addSubview(self.childViewController!.view)
    self.childViewController!.view.frame = CGRectMake (40, 200, 400, 250)
}
Run Code Online (Sandbox Code Playgroud)

ChildViewController

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    return  .All
}

override func shouldAutorotate() -> Bool {
    return true
}
Run Code Online (Sandbox Code Playgroud)

Xcode部署信息中支持的方向设置为全部四个.

我得到了什么:

没有View的旋转.如果我将父级的旋转设置为all,则所有视图一起旋转.所以它是全有或全无. …

xcode uiviewcontroller landscape-portrait childviewcontroller swift

24
推荐指数
2
解决办法
5803
查看次数

为Android手机和平板电脑创建不同的布局

这是一个基本的android问题.我有app需要为手机和平板电脑设置不同的屏幕.手机需要有一个ListView,平板电脑需要有一个GridView的项目.

我想知道如何在不制作两个不同的应用程序的情况下做到这一点.

谢谢

android landscape-portrait

23
推荐指数
3
解决办法
3万
查看次数

如何防止Phonegap应用程序切换到横向视图

这个应该很简单,但事实并非如此.我试图阻止我的应用程序进入横向视图,所以我已经改变了config.xml这样的文件:<preference name="orientation" value="portrait" />.不幸的是,它没有用.有任何想法吗?

app-config landscape config landscape-portrait cordova

21
推荐指数
3
解决办法
1万
查看次数

Android - 在横向和纵向模式之间切换会使Intent失去价值

我正在使用Intents在我的Android应用程序中切换活动.我将数据放入Intent以用于下一个活动.当我在横向和纵向模式之间切换手机时,从意图传递的值将丢失,我得到NullPointerException.

有人可以告诉我可能有什么问题.

有很多代码可以完全发布.但如果有人需要查看代码的特定部分,我可以在此处发布.

编辑
我解决了状态未被保存的问题.但我遇到的另一个问题是,在方向改变后屏幕上没有任何按钮工作.按下按钮,我在LogCat中收到此警告

02-25 23:07:49.190: WARN/WindowManager(58): No window to dispatch pointer action 0
Run Code Online (Sandbox Code Playgroud)

请帮忙.

android landscape-portrait android-orientation

20
推荐指数
3
解决办法
6万
查看次数

UIDeviceOrientationFaceUp - 如何区分肖像和风景?

我试图找出设备是纵向还是横向模式.如果设备没有朝上,我的代码工作得很好.如果它面朝上(和方向== 5),它将无法区分肖像和风景.如果UIDeviceOrientation是FaceUp,有没有在风景/肖像方面确定"方向"?

我的代码:

UIDeviceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation];

NSLog(@"orientation: %d", interfaceOrientation);

if (interfaceOrientation == UIDeviceOrientationIsLandscape(interfaceOrientation)) {
    NSLog(@"LANDSCAPE!!!");
}

if (interfaceOrientation == UIDeviceOrientationIsPortrait(interfaceOrientation)) {
    NSLog(@"PORTRAIT!!!");
}
Run Code Online (Sandbox Code Playgroud)

iphone cocoa-touch ipad landscape-portrait uideviceorientation

19
推荐指数
2
解决办法
8574
查看次数

Android - 如何使用相机getSupportedPreviewSizes()进行纵向方向

我正在尝试在活动中嵌入相机预览.它只是在纵向方向.问题是预览被拉长了.

我试图选择最佳尺寸.但问题是所有支持的预览尺寸都来自getSupportedPreviewSizes()横向返回尺寸.因此,根据我的代码选择正确的大小我认为不行.

我的布局XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_take_attendance"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:orientation="vertical"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.lab.rafael.smartattendance.TakeAttendanceActivity">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/take_attendance_label"
        android:id="@+id/take_attendance_label"
        android:layout_marginBottom="@dimen/activity_vertical_margin"/>

    <!-- camera preview container -->
    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="@color/red"
        android:id="@+id/take_attendance_scan_qr_frame"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <EditText
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:hint="@string/take_attendance_manual_text"
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/take_attendance_manual_button"
            android:id="@+id/take_attendance_manual_button"/>
    </LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

这是我的CameraPreview班级:

package com.lab.rafael.smartattendance.camera;

import android.content.Context;
import android.hardware.Camera;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import java.io.IOException;
import java.util.List;

public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { …
Run Code Online (Sandbox Code Playgroud)

java user-interface camera android landscape-portrait

17
推荐指数
1
解决办法
4320
查看次数