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 scrubbersUISemanticContentAttributeSpatial, // 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 gameUISemanticContentAttributeForceLeftToRight,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的几个枚举定义相关推荐

  1. python3 枚举定义和使用

    定义 在某些情况下,一个类的对象是有限且固定的,比如季节类,它只有 4 个对象:再比如行星类,目前只有 8 个对象.这种实例有限且固定的类,在 Python 中被称为枚举类. 程序有两种方式来定义枚举 ...

  2. 使用枚举定义常量更好点儿

    大家好,欢迎来到雄雄的小课堂,昨天给大家分享的是"java中的Queue队列的用法示例",今天,分享的主题是"java中,推荐使用枚举定义常量". 前言:常量, ...

  3. c语言 枚举定义变量,C语言之枚举的定义以及测试

    #include /*   定义方法1:只定义枚举类型,不定义变量 enum week { SUN,        // SUN = 0 MON,        // MON = 1; TUE, WE ...

  4. 【swift3.0】【枚举定义的不同方式】

    为什么80%的码农都做不了架构师?>>>    贡献作者 -[XJDomain] 博客XJ:  https://my.oschina.net/shengbingli/blog Git ...

  5. JAVA的枚举定义和使用

    1.什么是枚举用enum修饰是一种特殊的类,但枚举是类,使用枚举可以很方便的定义常量 枚举的概念:枚举类是一种特殊形式的Java类,枚举类的对象个数是有限且明确的 为什么需要枚举: 因为一些方法在运行 ...

  6. java 枚举定义变量_Java枚举(enum)

    Free Talk 上学期上Java课时都没有听说过枚举的概念,这次偶然在JavaGuide博客中看到了,就想写一些枚举相关知识.本篇文章会较为深入地讲解一下枚举的强大功能. 写这边博客的时候,又发现 ...

  7. java如何枚举定义一个数组_java 枚举(Enum)笔记

    枚举 枚举类型是指由一组固定的常量组成合法的类型,由 enum 关键字来定义一个枚举类型. 定义 pulic enum Season{ SPRING(1),SUMMER(2),AUTUMN(3),WI ...

  8. java如何枚举定义一个数组_Java中如何将字符枚举类变成一个数组

    ( light. class ); currenummap.put(light. red , " 红灯 " ); currenummap.put(light. green , &q ...

  9. Js 枚举定义Layer Icon

    layer的icon有7种样式:1-7 [图片来自:https://blog.csdn.net/beauxie/article/details/60959971] 有时候常常记不住 

最新文章

  1. Linux多线程与同步
  2. html手机不能自动播放音乐,解决移动端浏览器 HTML 音频不能自动播放的三种方法...
  3. POJ 2456 Aggressive cows(二分答案)
  4. android toolbar 开发总结
  5. 莉莉丝最新大作《末日余晖》首曝CG,揭秘美术制作幕后
  6. 写文件+三剑客+别名
  7. 用栈来求解汉诺塔变形问题
  8. c可以 char* 赋值但是c++不可以_雷佳音的妻子完全可以女团C位出道,这么有气质的女人,谁能不爱...
  9. 【LeetCode】智商题 brainteaser(共3题)
  10. Python符号计算入门及隐函数图像绘制
  11. [算法模板]莫比乌斯反演
  12. 【iphone】 如何将app发布到appstore中
  13. stm32中如何避免等待_地坪漆施工中如何避免常见的小问题
  14. 3D动态相册实现代码
  15. 基于米思齐的电磁炮基础代码
  16. baidu patchrom项目 make后刷机包脚本多一个0解决
  17. 家用宽带搭建个人服务器(二)
  18. SPM软件的参考资料链接
  19. MySQL深入了解与性能优化
  20. javascript 获取具体id

热门文章

  1. 送书拉!给开发者们的几本书籍 |福利
  2. 2011寒假-操作系统学习笔记
  3. nginx反向代理、负载均衡、动态请求
  4. RecyclerView 使用指南
  5. tomcat7.0 安装启动之后localhost:8080页面进不去,提示错误500
  6. Mybatis联合查询
  7. 一站式学习Wireshark(三):应用Wireshark IO图形工具分析数据流 | 快课网
  8. postfix邮件系统经典退信
  9. 2008.04.14狼图腾
  10. 大名鼎鼎的Requests库用了什么编码风格?