iOS 工程默认只允许竖屏,在单独界面进行横竖转换,屏幕旋转

只含有 。关于横竖屏的代码

#import "InspectionReportViewController.h"

#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)

#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
@interface InspectionReportViewController ()<UIWebViewDelegate>
{
    UIWebView *webview;

    UIButton * back;

}
@end

@implementation InspectionReportViewController

-(BOOL)shouldAutorotate{

    return NO;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    // 如果该界面需要支持横竖屏切换
    return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortrait;
    // 如果该界面仅支持横屏
    // return UIInterfaceOrientationMaskLandscapeRight;
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];

}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];

}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

[self CreatUI];

    //横屏同志UIApplicationDidChangeStatusBarFrameNotification   UIDeviceOrientationDidChangeNotification
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange) name:UIDeviceOrientationDidChangeNotification object:nil];
}

-(void)CreatUI{

    self.view.backgroundColor = [UIColor blackColor];

    webview = [[UIWebView alloc] initWithFrame:self.view.bounds];
    webview.backgroundColor = [UIColor blackColor];

    [webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://60.205.188.204:8087/WebDcmviewer/dcmviewer.html?org_code=%@&check_id=%@",_org_code,_check_id]]]];

    webview.scalesPageToFit = YES;
    webview.scrollView.scrollEnabled = NO;
    [self.view addSubview:webview];

     back = [myButton buttonWithType:UIButtonTypeCustom frame:CGRectMake(ScreenWidth-IPHONEWIDTH(120), ScreenHeight-IPHONEHIGHT(100), IPHONEWIDTH(50), IPHONEHIGHT(50)) tag:1 image:@"ic_history_ct_return" andBlock:^(myButton *button) {

        [self.navigationController popViewControllerAnimated:YES];

    }];

    [self.view addSubview:back];

}

//横屏
- (void)deviceOrientationDidChange
{
    NSLog(@"deviceOrientationDidChange:%ld",(long)[UIDevice currentDevice].orientation);

    if([UIDevice currentDevice].orientation == UIDeviceOrientationPortrait) {

        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];

        [UIView animateWithDuration:0.1f animations:^{

            self.view.transform = CGAffineTransformMakeRotation(0);
       self.view.bounds = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);

            webview.frame = self.view.bounds;

            back.frame = CGRectMake(SCREEN_WIDTH-IPHONEWIDTH(80), SCREEN_HEIGHT-IPHONEHIGHT(100), IPHONEHIGHT(60), IPHONEHIGHT(60));

        }];

        //注意: UIDeviceOrientationLandscapeLeft 与 UIInterfaceOrientationLandscapeRight
    } else if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft ) {

        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];

        [UIView animateWithDuration:0.1f animations:^{

            self.view.transform = CGAffineTransformMakeRotation(M_PI_2);

            self.view.bounds = CGRectMake(0, 0, SCREEN_HEIGHT, SCREEN_WIDTH);

            webview.frame = self.view.bounds;

            back.frame = CGRectMake(SCREEN_WIDTH-IPHONEWIDTH(80), SCREEN_HEIGHT-IPHONEHIGHT(100), IPHONEHIGHT(60), IPHONEHIGHT(60));

        }];

    }else if ( [UIDevice currentDevice].orientation== UIDeviceOrientationLandscapeRight){

        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft];

        [UIView animateWithDuration:0.1f animations:^{

            self.view.transform = CGAffineTransformMakeRotation(-M_PI_2);

         self.view.bounds = CGRectMake(0, 0,SCREEN_HEIGHT, SCREEN_WIDTH);

            webview.frame = self.view.bounds;

            back.frame = CGRectMake(SCREEN_WIDTH-IPHONEWIDTH(80), SCREEN_HEIGHT-IPHONEHIGHT(100), IPHONEHIGHT(60), IPHONEHIGHT(60));

        }];
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
时间: 2024-08-08 01:28:47

iOS 工程默认只允许竖屏,在单独界面进行横竖转换,屏幕旋转的相关文章

iOS界面设置竖屏,个别界面强制横屏

项目需要,只有某个界面需要横屏显示,其它全只支持竖屏显示即可,网上资料很多,但是试过都不好用,最后发现是因为我的项目UIViewController外层是UINavigationVeiwController,只在UIViewController重载supportedInterfaceOrientations与shouldAutorotate 方法是不行的. 下面说明具体设置步骤:(参考http://www.cocoachina.com/bbs/read.php?tid-244095.html)

iOS的横屏(Landscape)与竖屏(Portrait)InterfaceOrientation

转自:http://www.molotang.com/articles/1530.html 接着上篇写的触摸事件,这次借机会整理下iOS横屏和竖屏的翻转方向支持,即InterfaceOrientation相关的内容. 最近做一个页面,最初并没有太多考虑orientation的情况,当其嵌入到一个在iPad上使用横屏(Landscape)的应用中,就会只显示在屏幕的左面,而且貌似还没显示全,这个……很丑!发自内心地觉得这么做对不起苹果的设计理念!对不起乔老爷子... 改!说到该就要了解苹果开发中对

Android和iOS中Cocos2dx的横屏竖屏设置

一.横屏.竖屏设置 1.android AndroidManifest.xml文件中, screenOrientation="landscape" 为横屏, screenOrientation="portrait"为竖屏 2.iOS - (NSUInteger) supportedInterfaceOrientations{ #ifdef __IPHONE_6_0 // 横屏显示 // return UIInterfaceOrientationMaskLandsca

activity在配置只支持竖屏时要注意个问题

如果界面不支持横屏,配置的时候,记得配置属性如下:android:screenOrientation="portrait"如果同时又配置了android:configChanges="orientation|screenSize|keyboardHidden|keyboard|navigation"记得不要配置orientation,有这个属性的时候,横屏,如果屏幕一直亮着,在不会调用onConfigurationChanged但是如果横屏,然后灭屏幕,等activ

Android横屏竖屏切换的问题

一.禁止横竖屏转换 Android横竖屏切换在手机开发中比较常见,很多软件在开发过程中为了避免横竖屏切换时引发不必要的麻烦,通常禁止掉横竖屏的切换, 通过在AndroidManifest.xml中设置activity中的android:screenOrientation属性值来实现. 比如下列设置 android:screenOrientation="portrait" 则无论手机如何变动,拥有这个属性的activity都将是竖屏显示. android:screenOrientatio

发现竖屏应用其实可以不用适配的了 惊喜

今天通过配置启动图发现了一个可以不用适配竖屏应用的方法了 即可以不用Autolayout 就可以快速开发了 但是得有几个前提:1:必须将App Icon and Lauch Images 配置成这样的 2:这种只针对竖屏App 3:   只能在xib上面拖拽,不能用代码写,既不能写frame 4:项目必须配置默认的启动图片:(如下) 这些都配置好之后就可以随心所欲了 不用管所谓的适配了(已验证过了) 再提一遍:这是只针对竖屏应用的 同时讲述一下我个人对适配的了解:1:Autolayout其实不能

Android4.0强制横屏竖屏

Android的启动默认是横屏或者竖屏我们的TV本来是横屏显示,但是有客户竟然要竖屏显示,昨天快下班收到的需求,竟然说7.19就要搞定.思路有2个,一个就是修改LCD的默认输出,但是这个不是我这个水平能轻而易举搞定的.另外一个就是底层应该给上层porting出接口.像这种系统性的接口一般在build.prop里.找到一个相关度比较大的属性ro.sf.hwrotation=270,和旋转有关的,联想到0,90,180,270.试试吧,将其改为ro.sf.hwrotation=0,测试了一下,OK,

ionic2/3 禁止屏幕旋转,禁止横屏,竖屏

ionic2/ionic3禁止屏幕旋转,及解除禁止旋转 1.添加插件: cmd到项目目录---> cordova plugin add cordova-plugin-screen-orientation 详情看https://github.com/apache/cordova-plugin-screen-orientation import { Component } from '@angular/core'; import { Platform } from 'ionic-angular';

Android 判断当前屏幕是横屏还是竖屏

记录学习 /**  * 返回当前屏幕是否为竖屏.  * @param context  * @return 当且仅当当前屏幕为竖屏时返回true,否则返回false.  */  public static boolean isScreenOriatationPortrait(Context context) {  return context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PO