- 我的app在iOS7上的UI一直有些问题,好在如果用XCode 4.x 编译打出来的包,在iOS7真机上没出现问题,所以一直懒得调代码。。
- 最近听朋友说,AppStore从2014年2月份起,就不接受XCode 5.0以下打包了(如果你传XCode4.x打的包会被rejected),不知道真的假的?不管真假吧,这事早晚要做,那就整整。。
- 首先是view controller的view的frame问题,在iOS7中是布满整个屏幕的,为了兼容老代码,首先让屏幕尺寸和此前一致,于是在我的BaseViewController的ViewDidLoad中,调用:
[代码]c#/cpp/oc代码:
1 |
if ([self
respondsToSelector:@selector(edgesForExtendedLayout)]) |
2 |
self.edgesForExtendedLayout
= UIRectEdgeNone; |
然后是NavigationBar的背景又折腾了一下,以前的背景高度不够,现在要算上status bar的高度20,拿PS给背景图加了40px高度(2x图),然后重新为UINavigationBar apearance 设置了一下background Image。有一点要注意的是通常我们不希望改掉系统弹出的VC的导航条背景,比如发邮件那个MFMailCompositeController,所以可以subclass一个Navigation Controller,然后app里面都用这个NC,自定义背景的时候使用:
[代码]c#/cpp/oc代码:
1 |
[UINavigationBar
appearanceWhenContainedIn:[CustomNavigationController class ],
nil]; |
就不会影响系统导航条了。
然后,就是TableView cell的背景问题,iOS7里面默认都是白色了,以前默认是clearColor,所以很多地方要改。一开始我把所有的cell初始化为Clear背景色,iPhone上看起来ok,不过iPad上就不行,还是个白背景,于是找来文档一看,发现需要实现一下tableView的willDispplay Cell这个delegate方法:
[代码]c#/cpp/oc代码:
1 |
-
( void )tableView:(UITableView
*)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { |
2 |
cell.backgroundColor
= GGSharedColor.clear; |
3 |
} |
最后是TextView的问题,iOS7上用contentSize取的size不准确,于是google了一下,改成这样:
[代码]c#/cpp/oc代码:
1 |
int textviewHeight
= textView.contentSize.height; |
2 |
if ([GGUtils
isIOS7]) { |
3 |
CGRect
tvRc = [textView.layoutManager usedRectForTextContainer:_tvContent.textContainer]; |
4 |
textviewHeight
= tvRc.size.height + 10; |
5 |
} |
差不多就这些,现在app看起来没什么毛病了。。有什么问题再慢慢调,就写到这里了。
补充一点,如何隐藏statusBar:
The way to resolve this depends on the value of the "View controller-based status bar appearance" setting in your
app's plist.
If "View controller-based status bar appearance" is NO in your plist, then this code should work:
[代码]c#/cpp/oc代码:
1 |
[[UIApplication
sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade]; |
If "View controller-based status bar appearance" is on, in your view controllers, add this method:
[代码]c#/cpp/oc代码:
1 |
-
(BOOL) prefersStatusBarHidden { |
2 |
//
I've hardcoded to YES here, but you can return a dynamic value to meet your needs for toggling |
3 |
return YES; |
4 |
} |
For toggling, when you want to change whether the status bar is hidden/shown based on the value of the above method, your view controller can call the setNeedsStatusBarAppearanceUpdate method.