不容错过的iOS 8的导航交互
2016-06-22 09:11
645 查看
你曾注意过Safari移动客户端里美轮美奂的导航栏缩放效果么,以及那些tab bar是如何消失的吗?
![](http://cn.cocos2d-x.org/uploads/20140923/1411446175147033.gif)
在iOS 8中,苹果让这种类型的交互变得非常容易,虽然在WWDC上演示了缩放导航栏效果,不过后来他们用隐藏导航的方式替代了这个想法,但tab bar不包括在内(我猜想他们后期会添加隐藏标签栏的属性)。
以下是iOS 8中非常酷的导航交互方式,可以让用户看到更多内容。
滚动页面时隐藏Bar
如果你有一个Table View,仅需要将导航控件的hidesBarsOnSwipe属性设置为true就OK了。
注意导航栏的行为会影响到在你的导航堆栈里所有的视图控件,所以如果你希望某一视图控控件的导航条不会跟着隐藏的话,你需要设置一下viewDidAppear。
点击时隐藏
![](http://cn.cocos2d-x.org/uploads/20140923/1411446108905491.gif)
如果你的视图并不像上面所示那样的卷动的话,你可以试着将hidesBarsOnTap的属性设置为true.
请注意,如果你之前在导航栈中某个视图控件里设置过hidesBarOnSwipe,你需要再次将其赋值为false以避免这个视图会发生像其他的视图那样的行为。同样的,如果对于Table View也曾有过设置,那你仍需要重新将navigationController?.hidesBarsOnTap设为false避免出错。
展示键盘输入时隐藏
![](http://cn.cocos2d-x.org/uploads/20140923/1411446309633961.gif)
如上图,使用导航控件的新特性hidesBarsWhenKeyboardAppears,你可以在输入键盘出现时将导航栏隐藏:
为了确保用户在使用时可以轻易的唤出隐藏的导航栏,你应该在需要的时候将hidesBarsOnTap或者hidesBarsOnSwipe设置为true.
其他特性
下面演示的是其他新的导航控制器属性,你可以看一下:
![](http://cn.cocos2d-x.org/uploads/20140923/1411446175147033.gif)
在iOS 8中,苹果让这种类型的交互变得非常容易,虽然在WWDC上演示了缩放导航栏效果,不过后来他们用隐藏导航的方式替代了这个想法,但tab bar不包括在内(我猜想他们后期会添加隐藏标签栏的属性)。
以下是iOS 8中非常酷的导航交互方式,可以让用户看到更多内容。
滚动页面时隐藏Bar
如果你有一个Table View,仅需要将导航控件的hidesBarsOnSwipe属性设置为true就OK了。
class QuotesTableViewController: UITableViewController { override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) navigationController?.hidesBarsOnSwipe = true } }
注意导航栏的行为会影响到在你的导航堆栈里所有的视图控件,所以如果你希望某一视图控控件的导航条不会跟着隐藏的话,你需要设置一下viewDidAppear。
点击时隐藏
![](http://cn.cocos2d-x.org/uploads/20140923/1411446108905491.gif)
如果你的视图并不像上面所示那样的卷动的话,你可以试着将hidesBarsOnTap的属性设置为true.
class QuoteImageViewController: UIViewController { override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) // 将hidesBarsOnSwift设置为false // 在此后的这个条件下它不会有任何效果 // 不过在上一个VC中它被设置成了true navigationController?.hidesBarsOnSwipe = false // setting hidesBarsOnTap to true navigationController?.hidesBarsOnTap = true } }
请注意,如果你之前在导航栈中某个视图控件里设置过hidesBarOnSwipe,你需要再次将其赋值为false以避免这个视图会发生像其他的视图那样的行为。同样的,如果对于Table View也曾有过设置,那你仍需要重新将navigationController?.hidesBarsOnTap设为false避免出错。
展示键盘输入时隐藏
![](http://cn.cocos2d-x.org/uploads/20140923/1411446309633961.gif)
如上图,使用导航控件的新特性hidesBarsWhenKeyboardAppears,你可以在输入键盘出现时将导航栏隐藏:
class CreateQuoteTableViewController: UITableViewController { override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) navigationController?.hidesBarsOnSwipe = false // 这个例子恰到好处的结合了hidesBarsOnTap和hidesBarsWhenKeyboardAppears两个特性 // 这样用户可以轻松的唤回导航栏并保存 navigationController?.hidesBarsOnTap = true navigationController?.hidesBarsWhenKeyboardAppears = true } }
为了确保用户在使用时可以轻易的唤出隐藏的导航栏,你应该在需要的时候将hidesBarsOnTap或者hidesBarsOnSwipe设置为true.
其他特性
下面演示的是其他新的导航控制器属性,你可以看一下:
class UINavigationController : UIViewController { //... truncated /// When the keyboard appears, the navigation controller's navigationBar toolbar will be hidden. The bars will remain hidden when the keyboard dismisses, but a tap in the content area will show them. @availability(iOS, introduced=8.0) var hidesBarsWhenKeyboardAppears: Bool /// When the user swipes, the navigation controller's navigationBar & toolbar will be hidden (on a swipe up) or shown (on a swipe down). The toolbar only participates if it has items. @availability(iOS, introduced=8.0) var hidesBarsOnSwipe: Bool /// The gesture recognizer that triggers if the bars will hide or show due to a swipe. Do not change the delegate or attempt to replace this gesture by overriding this method. @availability(iOS, introduced=8.0) var barHideOnSwipeGestureRecognizer: UIPanGestureRecognizer { get } /// When the UINavigationController's vertical size class is compact, hide the UINavigationBar and UIToolbar. Unhandled taps in the regions that would normally be occupied by these bars will reveal the bars. @availability(iOS, introduced=8.0) var hidesBarsWhenVerticallyCompact: Bool /// When the user taps, the navigation controller's navigationBar & toolbar will be hidden or shown, depending on the hidden state of the navigationBar. The toolbar will only be shown if it has items to display. @availability(iOS, introduced=8.0) var hidesBarsOnTap: Bool /// The gesture recognizer used to recognize if the bars will hide or show due to a tap in content. Do not change the delegate or attempt to replace this gesture by overriding this method. @availability(iOS, introduced=8.0) unowned(unsafe) var barHideOnTapGestureRecognizer: UITapGestureRecognizer { get } }
相关文章推荐
- 安装测试版ios10和xcode8.0beta(8S128d)
- ios加载第三方库:横竖屏切换错误
- iOS开发——SiriKit应用
- iOS开发人员需要了解的苹果开发者账号与邓白氏编码
- iOS开发实战——摄像头与相册权限获取逻辑优化
- iOS开发--AVFoundation自定义相机
- 『零行代码』解决键盘遮挡问题(iOS)
- iOS Quartz2D基本图形绘制
- iOS 开发各种传值
- textView限制字数(超简单,不走弯路)(解决联想输入及iOS7崩溃等问题)
- IOS SingleView
- iOS之设置用户头像的圆角
- iOS之iPhone解锁界面的"滑动来解锁"闪烁动画效果,好奇的赶紧进来取走,别看了,说的就是你0.0
- openCV 2.4.13 iOS background_segm.hpp 'list' file not found
- vmstat 与 iostat使用
- iOS开发之使用XMPPFramework实现即时通信
- iOS dealloc 不执行或延迟执行的问题
- iOS:实现图片的无限轮播---之使用第三方库SDCycleScrollView
- 正则表达式总结
- ios 优化概念