首页 > 代码库 > UIView的几个枚举定义
UIView的几个枚举定义
UIView是iOS开发最基本的视图,很多控件都是继承它,掌握其中的几个基本枚举定义,有利益理解视图的加载和参数区别。
一、UIViewAnimationCurve
UIView的基本动画变化规律
typedef NS_ENUM(NSInteger, UIViewAnimationCurve) { UIViewAnimationCurveEaseInOut, // 淡入淡出 UIViewAnimationCurveEaseIn, // 开始时慢 UIViewAnimationCurveEaseOut, // 结束时慢 UIViewAnimationCurveLinear, //线性变化 };使用方法:
在UIView(UIViewAnimation)的动画分类中使用
+ (void)setAnimationCurve:(UIViewAnimationCurve)curve; // default = UIViewAnimationCurveEaseInOut
二、UIViewContentMode
内容模型,主要用于图片显示(是否变形)
总则:凡是没有带scale的,图片大小与content大小不一致,都不会变形,都有可能留下空白。
UIView的ContentMode图片填充
typedef NS_ENUM(NSInteger, UIViewContentMode) { UIViewContentModeScaleToFill, //完全填充,有可能拉伸 UIViewContentModeScaleAspectFit, //保证图片比例,但是人有可能会有空白 UIViewContentModeScaleAspectFill, //保证图片比例,而且占满,但是可能只会显示部分 UIViewContentModeRedraw, // redraw on bounds change (calls -setNeedsDisplay) UIViewContentModeCenter, // contents remain same size. positioned adjusted. UIViewContentModeTop, //对齐顶部 UIViewContentModeBottom, UIViewContentModeLeft, UIViewContentModeRight, UIViewContentModeTopLeft, UIViewContentModeTopRight, UIViewContentModeBottomLeft, UIViewContentModeBottomRight, };
使用方法:UIView(UIViewRendering)渲染
@property(nonatomic) UIViewContentMode contentMode; // default is UIViewContentModeScaleToFill
三、UIViewAnimationTransition
用于简单视图动画过渡。如果需要使用到更深层次的过渡在layer层加CATransition【传送门】
typedef NS_ENUM(NSInteger, UIViewAnimationTransition) { UIViewAnimationTransitionNone, //正常 UIViewAnimationTransitionFlipFromLeft, //从左往右翻 UIViewAnimationTransitionFlipFromRight, //从右往左翻 UIViewAnimationTransitionCurlUp, //从上往下卷 UIViewAnimationTransitionCurlDown, //从下网上卷 };使用方法:UIVeiw(UIViewAnimation) 动画
+ (void)setAnimationTransition:(UIViewAnimationTransition)transition forView:(UIView *)view cache:(BOOL)cache; // 只有在开始和结束动画块之间设置才有效果
四、UIViewAutoresizing
该定义用于自动调节子控件在父控件的位置和宽高,以保证可以适应多种屏幕。
这是一个位移型枚举,可以一次使用多种状态,本身也可以设置多种自动调整。
typedef NS_OPTIONS(NSUInteger, UIViewAutoresizing) { UIViewAutoresizingNone = 0, //不调整 UIViewAutoresizingFlexibleLeftMargin = 1 << 0, //自动调整View与父视图的左边距,保证右边距不变 UIViewAutoresizingFlexibleWidth = 1 << 1, //自动调整View宽度,保证左右边距不变 UIViewAutoresizingFlexibleRightMargin = 1 << 2, //自动调整view与父视图的右边距,保证左边距不变 UIViewAutoresizingFlexibleTopMargin = 1 << 3, //自动调整View与父视图的下边距,保证上边距不变 UIViewAutoresizingFlexibleHeight = 1 << 4, //自动调整View的高度,保证上下边距不变 UIViewAutoresizingFlexibleBottomMargin = 1 << 5 //自动调整View与父视图的上边距,保证下边距不变 };
方法使用:UIView(UIViewGeometry)几何
@property(nonatomic) UIViewAutoresizing autoresizingMask; // simple resize. default is UIViewAutoresizingNone
提示:这个枚举用于UIView的autoresizingMask属性值,自定义控件时常常需要设置。
五、UIViewAnimationOptions
该枚举主要用于动画过渡的,可以设置多个值,如果需要复杂动画还是得使用Core Animation。
这个为简单的动画方法的参数,简单设置可以实现动画。
1.常规动画属性设置(可以同时选择多个进行设置) UIViewAnimationOptionLayoutSubviews:动画过程中保证子视图跟随运动。**提交动画的时候布局子控件,表示子控件将和父控件一同动画。** UIViewAnimationOptionAllowUserInteraction:动画过程中允许用户交互。 UIViewAnimationOptionBeginFromCurrentState:所有视图从当前状态开始运行。 UIViewAnimationOptionRepeat:重复运行动画。 UIViewAnimationOptionAutoreverse :动画运行到结束点后仍然以动画方式回到初始点。**执行动画回路,前提是设置动画无限重复** UIViewAnimationOptionOverrideInheritedDuration:忽略嵌套动画时间设置。**忽略外层动画嵌套的时间变化曲线** UIViewAnimationOptionOverrideInheritedCurve:忽略嵌套动画速度设置。**通过改变属性和重绘实现动画效果,如果key没有提交动画将使用快照** UIViewAnimationOptionAllowAnimatedContent:动画过程中重绘视图(注意仅仅适用于转场动画)。 UIViewAnimationOptionShowHideTransitionViews:视图切换时直接隐藏旧视图、显示新视图,而不是将旧视图从父视图移除(仅仅适用于转场动画)**用显隐的方式替代添加移除图层的动画效果** UIViewAnimationOptionOverrideInheritedOptions :不继承父动画设置或动画类型。**忽略嵌套继承的选项** ---------------------------------------------------------------------------- 2.动画速度控制(可从其中选择一个设置)时间函数曲线相关**时间曲线函数** UIViewAnimationOptionCurveEaseInOut:动画先缓慢,然后逐渐加速。 UIViewAnimationOptionCurveEaseIn :动画逐渐变慢。 UIViewAnimationOptionCurveEaseOut:动画逐渐加速。 UIViewAnimationOptionCurveLinear :动画匀速执行,默认值。 ----------------------------------------------------------------------------- 3.转场类型(仅适用于转场动画设置,可以从中选择一个进行设置,基本动画、关键帧动画不需要设置)**转场动画相关的** UIViewAnimationOptionTransitionNone:没有转场动画效果。 UIViewAnimationOptionTransitionFlipFromLeft :从左侧翻转效果。 UIViewAnimationOptionTransitionFlipFromRight:从右侧翻转效果。 UIViewAnimationOptionTransitionCurlUp:向后翻页的动画过渡效果。 UIViewAnimationOptionTransitionCurlDown :向前翻页的动画过渡效果。 UIViewAnimationOptionTransitionCrossDissolve:旧视图溶解消失显示下一个新视图的效果。 UIViewAnimationOptionTransitionFlipFromTop :从上方翻转效果。 UIViewAnimationOptionTransitionFlipFromBottom:从底部翻转效果。
使用方式:UIView(UIViewAnimationWithBlocks)
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); + (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay usingSpringWithDamping:(CGFloat)dampingRatio initialSpringVelocity:(CGFloat)velocity options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(7_0); + (void)transitionWithView:(UIView *)view duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^ __nullable)(void))animations completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); + (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); // toView added to fromView.superview, fromView removed from its superview + (void)performSystemAnimation:(UISystemAnimation)animation onViews:(NSArray<__kindof UIView *> *)views options:(UIViewAnimationOptions)options animations:(void (^ __nullable)(void))parallelAnimations completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(7_0);
六、UIViewKeyframeAnimationOptions
该定义也是用于动画的,但是这个是可以通过关键帧,减少前几种动画方式的代码嵌套和代码量过多问题【区别和使用实例】
typedef NS_OPTIONS(NSUInteger, UIViewKeyframeAnimationOptions) { UIViewAnimationOptionLayoutSubviews//进行动画时布局子控件 UIViewAnimationOptionAllowUserInteraction//进行动画时允许用户交互 UIViewAnimationOptionBeginFromCurrentState//从当前状态开始动画 UIViewAnimationOptionRepeat//无限重复执行动画 UIViewAnimationOptionAutoreverse//执行动画回路 UIViewAnimationOptionOverrideInheritedDuration//忽略嵌套动画的执行时间设置 UIViewAnimationOptionOverrideInheritedOptions//不继承父动画设置 UIViewKeyframeAnimationOptionCalculationModeLinear//运算模式:连续 UIViewKeyframeAnimationOptionCalculationModeDiscrete//运算模式:离散 UIViewKeyframeAnimationOptionCalculationModePaced//运算模式:均匀执行 UIViewKeyframeAnimationOptionCalculationModeCubic//运算模式:平滑 UIViewKeyframeAnimationOptionCalculationModeCubicPaced//运算模式:平滑均匀 } NS_ENUM_AVAILABLE_IOS(7_0);
使用方法:UIView(UIViewkeyframeAnimation)关键帧动画
+ (void)animateKeyframesWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewKeyframeAnimationOptions)options animations:(void (^)(void))animations completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(7_0);
UIView动画方式和参数枚举
其他枚举
//移除view结束 typedef NS_ENUM(NSUInteger, UISystemAnimation) { UISystemAnimationDelete, // removes the views from the hierarchy when complete } NS_ENUM_AVAILABLE_IOS(7_0); 使用方法: + (void)performSystemAnimation:(UISystemAnimation)animation onViews:(NSArray<__kindof UIView *> *)views options:(UIViewAnimationOptions)options animations:(void (^ __nullable)(void))parallelAnimations completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(7_0); //用于字体设置的 typedef NS_ENUM(NSInteger, UIViewTintAdjustmentMode) { UIViewTintAdjustmentModeAutomatic, UIViewTintAdjustmentModeNormal, UIViewTintAdjustmentModeDimmed, //字体模式 暗灰色 } NS_ENUM_AVAILABLE_IOS(7_0); 使用属性: @property(nonatomic) UIViewTintAdjustmentMode tintAdjustmentMode NS_AVAILABLE_IOS(7_0); typedef NS_ENUM(NSInteger, UISemanticContentAttribute) { UISemanticContentAttributeUnspecified = 0, UISemanticContentAttributePlayback, // for playback controls such as Play/RW/FF buttons and playhead scrubbers UISemanticContentAttributeSpatial, // for controls that result in some sort of directional change in the UI, e.g. a segmented control for text alignment or a D-pad in a game UISemanticContentAttributeForceLeftToRight, UISemanticContentAttributeForceRightToLeft } NS_ENUM_AVAILABLE_IOS(9_0); 使用方法: @property (nonatomic) UISemanticContentAttribute semanticContentAttribute NS_AVAILABLE_IOS(9_0); // This method returns the layout direction implied by the provided semantic content attribute relative to the application-wide layout direction (as returned by UIApplication.sharedApplication.userInterfaceLayoutDirection). + (UIUserInterfaceLayoutDirection)userInterfaceLayoutDirectionForSemanticContentAttribute:(UISemanticContentAttribute)attribute NS_AVAILABLE_IOS(9_0); // This method returns the layout direction implied by the provided semantic content attribute relative to the provided layout direction. For example, when provided a layout direction of RightToLeft and a semantic content attribute of Playback, this method returns LeftToRight. Layout and drawing code can use this method to determine how to arrange elements, but might find it easier to query the container view’s effectiveUserInterfaceLayoutDirection property instead. + (UIUserInterfaceLayoutDirection)userInterfaceLayoutDirectionForSemanticContentAttribute:(UISemanticContentAttribute)semanticContentAttribute relativeToLayoutDirection:(UIUserInterfaceLayoutDirection)layoutDirection NS_AVAILABLE_IOS(10_0);
UIView的几个枚举定义
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。