let orientation: UIInterfaceOrientation = UIApplication.sharedApplication().statusBarOrientation println("Currently landscape: " + ((orientation == UIInterfaceOrientation.LandscapeLeft||orientation == UIInterfaceOrientation.LandscapeRight) ?"YES":"NO")) println("UIScreen.mainScreen().bounds: \(UIScreen.mainScreen().bounds)") println("UIScreen.mainScreen().applicationFrame: \(UIScreen.mainScreen().applicationFrame)")
在ios7中输出:
Currently landscape: NO
UIScreen.mainScreen().bounds: (0.0,0.0,320.0,568.0)
UIScreen.mainScreen().applicationFrame: (0.0,20.0,320.0,548.0)
Currently landscape: YES
UIScreen.mainScreen().bounds: (0.0,0.0,320.0,568.0)
UIScreen.mainScreen().applicationFrame: (20.0,0.0,300.0,568.0)
在ios8中输出:
Currently landscape: NO
UIScreen.mainScreen().bounds: (0.0,0.0,320.0,568.0)
UIScreen.mainScreen().applicationFrame: (0.0,20.0,320.0,548.0)
Currently landscape: YES
UIScreen.mainScreen().bounds: (0.0,0.0,568.0,320.0)
UIScreen.mainScreen().applicationFrame: (0.0,0.0,568.0,320.0)
结论:
1、在ios7中UIScreen.mainScreen().bounds是固定不变的值,在ios8中他的值是随横竖屏改变的!
为了在ios8中得到原来的效果可以:
+ (CGSize)screenSize { CGSize screenSize = [UIScreen mainScreen].bounds.size; return CGSizeMake(MIN(screenSize.width, screenSize.height), MAX(screenSize.width, screenSize.height)); }
2、
在ios8中增加了2个属性:
nativeBounds : 屏幕像素,不随横竖平改变的!
nativeScale :1(non retina)/2(retina)/3(retina hd)
ios8输出:
Currently landscape: YES
UIScreen.mainScreen().bounds: (0.0,0.0,568.0,320.0)
UIScreen.mainScreen().applicationFrame: (0.0,20.0,568.0,300.0)
UIScreen.mainScreen().nativeBounds: (0.0,0.0,640.0,1136.0)
UIScreen.mainScreen().nativeScale: 2.0
Currently landscape: NO
UIScreen.mainScreen().bounds: (0.0,0.0,320.0,568.0)
UIScreen.mainScreen().applicationFrame: (0.0,20.0,320.0,548.0)
UIScreen.mainScreen().nativeBounds: (0.0,0.0,640.0,1136.0)
UIScreen.mainScreen().nativeScale: 2.0
3、从UIScreen.mainScreen().applicationFrame输出值看出,ios8默认横屏statusbar是隐藏掉了。你可以根据plist中
View controller-based status bar appearance的值的不同来用
UIApplication.sharedApplication().setStatusBarHidden(false, withAnimation: UIStatusBarAnimation.None)
或
override func prefersStatusBarHidden() -> Bool { return false }
显示横屏statusbar
相关推荐
重力感应imageView/A grivity ImageView 可以重力感应控制imageView左右滑动的控件,使用方法简单四步: YGGravityImageView *imageView = [[YGGravityImageView ...Xcode 7.3.1编译通过,iOS 9.x、8.x测试通过
#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width) #define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height) //-------------------获取设备大小----判断5--------------------- #define...
menuFrame:CGRectMake([UIScreen mainScreen].bounds.size.width-125- 10, 136, 125, 115) clickIndexHandle:^(NSInteger index) { switch (index) { case 0://这个是选中哪一行的时候的输出,或者执行的动作,...
iOS 工具类,NSString,UIImage等。###目前包括以下几类 * UIImage * UIScreen * UIView * NSString
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds]; MainController *mainVc = [[MainController alloc]init]; // 设置根控制器 self.window.rootViewController = mainVc; ...
对于加载网络图片时,Demo中使用了YYWebImage,也可自行替换成SDWebImage。 3.重写了和系统UIPageControl一样的功能,可用图片代替PageControl上的点点,也可自定义其颜色以及切换动画。 使用方法:使用方法比较...
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; UILabel *label...
ImageScrollView *imgScrollView = [[ImageScrollView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 200)]; [self.view addSubview:imgScrollView]; //添加数据 ...
window = UIWindow(frame: UIScreen.main.bounds) if !UserDefaults.standard.bool(forKey: "alreadyUsedApp"){ // 未使用过App,首次使用 let images:[UIImage] = [UIImage(named:"1")!,UIImage(named:...
runtime字体大小适配 (void)load{ //获取替换后的类方法 Method newMethod = class_... newFont = [UIFont adjustFont:fontSize * [UIScreen mainScreen].bounds.size.width/YourUIScreen]; return newFont; }
UIScreen *screen = [UIScreen mainScreen]; //获得屏幕的大小 CGRect rect = screen.bounds; //判断btn这个指针指向的是UIButton的对象的时候才清空 if([btn isKindOfClass:[UIButton class]]){ [btn ...
借鉴相关资料,整理了一个很有意思的button动画效果,iOS自定义UIButton点击动画特效 先看一下效果图: 下面贴上代码: ViewController: #import @interface ViewController : UIViewController @end #import ...
focusView3.frame = CGRectMake(20, 20, [UIScreen mainScreen].bounds.size.width-40, [UIScreen mainScreen].bounds.size.height-40); [self.view addSubview:focusView3]; focusView3.delegate =self; ...
保存照片到系统相册 保存照片到系统相册这个功能很多社交...#define SCREEN [UIScreen mainScreen].bounds.size self.image = [UIImage imageNamed:@”iOSDevTip”]; UIImageView *imageView = [[UIImageView alloc] in
ImageScrollView *imgScrollView = [[ImageScrollView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 200)]; [self.view addSubview:imgScrollView]; //添加数据 ...
宏定义在C系开发中可以说占有举足轻重的作用,为了简化开发流程,提升工作效率,收集了一些平时常用的宏定义,今后会不定期更新 1.UI元素 //NavBar高度 #define NAVIGATIONBAR_HEIGHT 44 //StatusBar高度 #define ...
此篇文章给大家描写如何写自定义九宫格,因为在开发中,这种需求也是常见不少。因此,主要利用UIButton阐述的; 实列不复杂,就两三个步骤完成: 一、定义宽度与高度(self.view) #define SCREEN_WIDTH [UIScreen ...
那么提到了 APP的混合模式开发,在Android开发中有WebView作为混合模式开发的桥梁,当然在IOS中也同样有一个 UIWebView 组件来作为混合模式开发的桥梁,那么下面就对UIWebView的一些基本知识详解一下。 一、...
在iOS中,有一个概念叫做像素对齐,如果像素不对齐,那么在GPU渲染时,需要进行插值计算,这个插值计算的过程会有性能损耗。 在模拟器上,有一个选项可以把像素不对齐的部分显示出来。 逻辑像素与物理像素 在iOS...