iOS7开发技巧

和任何新的iOS版本一样,有着一堆堆的新技巧和修改需要处理.有些我并不会立即遇到,所以这篇文章并不是一套完整技巧汇总.只是分享一些我碰巧遇到的问题.

如果你有任何更多的发现,可以发Twitter或者email给我.我将免费一起汇入这篇文章.

Stealing The Blur

不幸的是,苹果并没有给你在views上直接使用模糊效果的方法.不过有一些聪明人采取修改UIToolbar的layer来做到iOS模糊. iOS-blur

你如果是想使用黑色风格的模糊,设置这个toolbar的barstyle为UIBarStyleBlack.

Tinting The Navbar

设置导航条的颜色,但是没有效果?原来还有另外一个设置色调的属性叫:'barTintColor'.

1  self.navigationController.navigationBar.barTintColor = [UIColor blueColor];

Nil Those Delegates

在 iOS7 上你需要在你controllers销毁之前,将 delegates and datasources 设置成 nil.否则你会有很多让人讨厌的' 'message sent to deallocated instance''异常

1  - (void)dealloc
2     {
3         self.tableView.delegate = nil;
4         self.tableView.dataSource = nil;
5     }

Hide The Status Bar

你是不是不喜欢透明的状态栏浮在内容的上面?是的,我也不喜欢.

标准的说法是不要在做任何诡计.

1  [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade]

在Info.plist里面设置UIViewControllerBasedStatusBarAppearance 为 YES,然后添加这个到你的controller里面

1  - (BOOL)prefersStatusBarHidden
2     {
3         return YES;
4     }

Changing The Status Bar Style Per Controller

在Info.plist里面设置UIViewControllerBasedStatusBarAppearance 为 YES,然后覆写:

1  - (UIStatusBarStyle)preferredStatusBarStyle
2  {
3      return UIStatusBarStyleLightContent;
4  }

Custom Back Button And Swipe Back

我发现唯一好的办法重写back按钮就是设置leftBarButtonItem,但是这样swipe 的手势又有问题了.幸运的是有一个非常简单的办法来修复

1  self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]
2                                              initWithImage:img
3                                              style:UIBarButtonItemStylePlain
4                                              target:self
5                                              action:@selector(onBack:)];
6     self.navigationController.interactivePopGestureRecognizer.delegate = (id<UIGestureRecognizerDelegate>)self;

Full Screen Content Transition

当内容全屏展示的时候(比如一个展开的视频),并且这时用户旋转方向,然后再关闭.你常常就会得到一个异常.这个情况就需要拿出preferredInterfaceOrientationForPresentation方法了.

1     - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
2     {
3         return UIInterfaceOrientationPortrait;
4     }

Checking For iOS 7

这不是什么新鲜方法.但是如果你只想在iOS7下执行可以这样写

1     if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
2         ...
3     } 

判断iOS7以下的话可以这样:

 1 NSUInteger DeviceSystemMajorVersion();
 2 
 3 NSUInteger DeviceSystemMajorVersion() {
 4 
 5         static NSUInteger _deviceSystemMajorVersion = -1;
 6 
 7         static dispatch_once_t onceToken;
 8 
 9         dispatch_once(&onceToken, ^{
10                 _deviceSystemMajorVersion = [[[[[UIDevice currentDevice] systemVersion] componentsSeparatedByString:@"."] objectAtIndex:0] intValue];
11         });
12         return _deviceSystemMajorVersion;
13 }
14 
15 #define IOS_VERSION_LOW_7 (DeviceSystemMajorVersion() < 7)

My Scroll View Is Moving!

iOS7 默认偏移你的scrollview 64px(20px的状态栏,44px的导航栏)

不过你依然可以禁用这个

1   self.automaticallyAdjustsScrollViewInsets = NO;

CocoaPods在iOS5有问题的

可以点击这个链接

posted @ 2013-10-10 21:22  yingkong1987  阅读(883)  评论(0编辑  收藏  举报