Edge Protect边缘保护
在冲突区域第一次执行手势的时候会优先触发App的内部手势,短时间内再次进行同样的操作则会触发系统手势。系统手势将会延迟到下一次执行
。相关方法:
@interface UIViewController (UIScreenEdgesDeferringSystemGestures)
// Override to return a child view controller or nil. If non-nil, that view controller's screen edges deferring system gestures will be used. If nil, self is used. Whenever the return value changes, -setNeedsScreenEdgesDeferringSystemGesturesUpdate should be called.
//该属性控制子视图控制器是否允许开发者控制edge protect的开启或是关闭。如果实现了这个方法并且有返回值子视图控制器的edge protect设置就会遵循父VC的设置,跟随父VC是否延迟执行系统手势。
@property (nonatomic, readonly, nullable) UIViewController *childViewControllerForScreenEdgesDeferringSystemGestures API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(watchos, tvos);
// Controls the application's preferred screen edges deferring system gestures when this view controller is shown. Default is UIRectEdgeNone.
//该属性是设置edge protect的方法,返回值是一个边界的枚举
//typedef NS_OPTIONS(NSUInteger, UIRectEdge) {
// UIRectEdgeNone = 0,
// UIRectEdgeTop = 1 << 0,
// UIRectEdgeLeft = 1 << 1,
// UIRectEdgeBottom = 1 << 2,
// UIRectEdgeRight = 1 << 3,
// UIRectEdgeAll = UIRectEdgeTop | UIRectEdgeLeft | UIRectEdgeBottom | UIRectEdgeRight
//} NS_ENUM_AVAILABLE_IOS(7_0);
//效果:通知中心、控制中心和HomeIndicator两次手势才能实现相应功能
@property (nonatomic, readonly) UIRectEdge preferredScreenEdgesDeferringSystemGestures API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(watchos, tvos);
// This should be called whenever the return values for the view controller's screen edges deferring system gestures have changed.
//这个方法用来动态控制edge protect,方法中返回一个BOOL变量根据需要改变该变量的值,可以控制是否需要edge protect
- (void)setNeedsUpdateOfScreenEdgesDeferringSystemGestures API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(watchos, tvos);
@end
使用场景:iPhone X横屏游戏为防止屏幕底部操作误触发上划呼出任务中心手势,需两次上划才能呼出任务中心。
Home Indicator隐藏/显示
当界面两秒内没有进行任何交互操作的时候Home Indicator会逐渐隐去,再次点击屏幕Home Indicator会逐渐出现,注意必须是点击,滑动并不能触发显示,效果只是隐藏(非永久),但是手势依然可以使用。相关方法:
@interface UIViewController (UIHomeIndicatorAutoHidden)
//方法使用与edge protect三个方法相同
// Override to return a child view controller or nil. If non-nil, that view controller's home indicator auto-hiding will be used. If nil, self is used. Whenever the return value changes, -setNeedsHomeIndicatorAutoHiddenUpdate should be called.
@property (nonatomic, readonly, nullable) UIViewController *childViewControllerForHomeIndicatorAutoHidden API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(watchos, tvos);
// Controls the application's preferred home indicator auto-hiding when this view controller is shown.
@property (nonatomic, readonly) BOOL prefersHomeIndicatorAutoHidden API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(watchos, tvos);
// This should be called whenever the return values for the view controller's home indicator auto-hiding have changed.
- (void)setNeedsUpdateOfHomeIndicatorAutoHidden API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(watchos, tvos);
@end
使用场景:iPhone X以后机型全屏播放视频时,屏幕误操作2秒后HomeIndicator自动隐藏,不会遮挡画面,增强沉浸感。
注意:prefersHomeIndicatorAutoHidden和preferredScreenEdgesDeferringSystemGestures不会同时生效,如果一起使用的话只有隐藏效果生效。