IOS7 UIScrollView & UINavigationController
2014-04-15 09:23
357 查看
解决IOS7 带来的导航栏问题,以及UIScrollView 布局问题~
实例:
I recently downloaded Xcode 5 DP to test my apps
in iOS 7. The first thing I noticed and confirmed is that my view's bounds is not always resized to account for the status bar and navigation bar.
In
I print the view's bounds:
{{0, 0}, {320, 568}}
This results in my content appearing below the navigation bar and status bar.
I know I could account for the height myself by getting the main screen's height, subtracting the status bar's height and navigation bar's height, but that seems like unnecessary extra work.
How can I fix this issue?
Update:
I've found a solution for this specific problem. Set the navigation bar's translucent property to NO:
This will fix the view from being framed underneath the navigation bar and status bar.
However, I have not found a fix for the case when you want the navigation bar to be translucent. For instance, viewing a photo full screen, I wish to have the navigation bar translucent, and the view to be framed underneath it. That works, but when I toggle
showing/hiding the navigation bar, I've experienced even stranger results. The first subview (a UIScrollView) gets its bounds y origin changed every time.
解决方案:
You can achieve this by implementing a new property called
iOS7 SDK. Please add the following code to achieve this,
You need to add the above in your
iOS 7 brings several changes to how you layout and customize the appearance of your UI. The changes in view-controller layout, tint color, and font
affect all the UIKit objects in your app. In addition, enhancements to gesture recognizer APIs give you finer grained control over gesture interactions.
Using View Controllers
In iOS 7, view controllers use full-screen layout. At the same time, iOS 7 gives you more granular control over the way a view controller lays out its views. In particular, the concept of full-screen layout has been refined to let a view controller specify
the layout of each edge of its view.
The
controller property is deprecated in iOS 7. If you currently specify
To adjust how a view controller lays out its views,
the following properties:
edgesForExtendedLayout
The
uses the
which specifies each of a rectangle’s four edges, in addition to specifying none and all. Use
specify which edges of a view should be extended, regardless of bar translucency. By default, the value of this property is
extendedLayoutIncludesOpaqueBars
If your design uses opaque bars, refine
also setting the
to NO. (The default value of
automaticallyAdjustsScrollViewInsets
If you don’t want a scroll view’s content insets to be automatically adjusted, set
(The default value of
topLayoutGuide, bottomLayoutGuide
The
indicate the location of the top or bottom bar edges in a view controller’s view. If bars should overlap the top or bottom of a view, you can use Interface Builder to position the view relative to the bar by creating constraints to the bottom of
to the top of bottomLayoutGuide. (If no bars should overlap the view, the bottom of
the same as the top of the view and the top of
the same as the bottom of the view.) Both properties are lazily created when requested.
Please refer, apple
doc
实例:
I recently downloaded Xcode 5 DP to test my apps
in iOS 7. The first thing I noticed and confirmed is that my view's bounds is not always resized to account for the status bar and navigation bar.
In
viewDidLayoutSubviews,
I print the view's bounds:
{{0, 0}, {320, 568}}
This results in my content appearing below the navigation bar and status bar.
I know I could account for the height myself by getting the main screen's height, subtracting the status bar's height and navigation bar's height, but that seems like unnecessary extra work.
How can I fix this issue?
Update:
I've found a solution for this specific problem. Set the navigation bar's translucent property to NO:
self.navigationController.navigationBar.translucent = NO;
This will fix the view from being framed underneath the navigation bar and status bar.
However, I have not found a fix for the case when you want the navigation bar to be translucent. For instance, viewing a photo full screen, I wish to have the navigation bar translucent, and the view to be framed underneath it. That works, but when I toggle
showing/hiding the navigation bar, I've experienced even stranger results. The first subview (a UIScrollView) gets its bounds y origin changed every time.
解决方案:
You can achieve this by implementing a new property called
edgesForExtendedLayoutin
iOS7 SDK. Please add the following code to achieve this,
if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) self.edgesForExtendedLayout = UIRectEdgeNone;
You need to add the above in your
-(void)viewDidLoadmethod.
iOS 7 brings several changes to how you layout and customize the appearance of your UI. The changes in view-controller layout, tint color, and font
affect all the UIKit objects in your app. In addition, enhancements to gesture recognizer APIs give you finer grained control over gesture interactions.
Using View Controllers
In iOS 7, view controllers use full-screen layout. At the same time, iOS 7 gives you more granular control over the way a view controller lays out its views. In particular, the concept of full-screen layout has been refined to let a view controller specify
the layout of each edge of its view.
The
wantsFullScreenLayoutview
controller property is deprecated in iOS 7. If you currently specify
wantsFullScreenLayout = NO, the view controller may display its content at an unexpected screen location when it runs in iOS 7.
To adjust how a view controller lays out its views,
UIViewControllerprovides
the following properties:
edgesForExtendedLayout
The
edgesForExtendedLayoutproperty
uses the
UIRectEdgetype,
which specifies each of a rectangle’s four edges, in addition to specifying none and all. Use
edgesForExtendedLayoutto
specify which edges of a view should be extended, regardless of bar translucency. By default, the value of this property is
UIRectEdgeAll.
extendedLayoutIncludesOpaqueBars
If your design uses opaque bars, refine
edgesForExtendedLayoutby
also setting the
extendedLayoutIncludesOpaqueBarsproperty
to NO. (The default value of
extendedLayoutIncludesOpaqueBarsis NO.)
automaticallyAdjustsScrollViewInsets
If you don’t want a scroll view’s content insets to be automatically adjusted, set
automaticallyAdjustsScrollViewInsetsto NO.
(The default value of
automaticallyAdjustsScrollViewInsetsis YES.)
topLayoutGuide, bottomLayoutGuide
The
topLayoutGuideand
bottomLayoutGuideproperties
indicate the location of the top or bottom bar edges in a view controller’s view. If bars should overlap the top or bottom of a view, you can use Interface Builder to position the view relative to the bar by creating constraints to the bottom of
topLayoutGuideor
to the top of bottomLayoutGuide. (If no bars should overlap the view, the bottom of
topLayoutGuideis
the same as the top of the view and the top of
bottomLayoutGuideis
the same as the bottom of the view.) Both properties are lazily created when requested.
Please refer, apple
doc
相关文章推荐
- UIButton使用方法汇总
- LigerUI 界面中,加上文本框限制输入长度功能!
- 1.注册或登录页面设计:UILabel,UIButton,UITextField
- 1.注册或登录页面设计:UILabel,UIButton,UITextField
- ueditor 编辑器的配置 实现了上传图片与文件功能---附效果图
- Xcode警告:Multiple build commands for output file
- HashMap和HashTable,HashMap中key和value的原理 - 跳刀的兔子 - 博客园
- break、continue跳出循环的深入学习
- Codeforces 416A Guess a number!(水题)
- Unique Paths II
- egit 出现问题 The current branch is not configured for pull No value for key branch.master.merge found i
- Unique Paths
- 在UEFI GPT分区下 用U盘安装win7X64的方法(win8也是类似)
- Longest Consecutive Sequence
- POJ 2778 DNA Sequence
- Web Design:给实验室UI们的一堂课(下)
- 利用addChildViewController组织viewController---类似UITabBarViewController的效果
- LeetCode:Longest Consecutive Sequence
- 数据库查询构建控件集Active Query Builder
- 数据库查询构建控件集Active Query Builder