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);
其它枚举
//移除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的几个枚举定义的更多相关文章
- [改善Java代码]推荐使用枚举定义常量
枚举和注解都是在Java1.5中引入的,虽然他们是后起之秀,但是功能不容小觑,枚举改变了常量的声明方式,注解耦合了数据和代码. 建议83:推荐使用枚举定义常量 一.分析 常量的声明是每一个项目中不可或 ...
- 拔高你的Java代码质量吧:推荐使用枚举定义常量(转)
提高你的Java代码质量吧:推荐使用枚举定义常量 一.分析 常量的声明是每一个项目中不可或缺的,在Java1.5之前,我们只有两种方式的声明:类常量和接口常量.不过,在1.5版之后有了改进,即新增了一 ...
- python3 枚举定义和使用
定义 在某些情况下,一个类的对象是有限且固定的,比如季节类,它只有 4 个对象:再比如行星类,目前只有 8 个对象.这种实例有限且固定的类,在 Python 中被称为枚举类.程序有两种方式来定义枚举类 ...
- 一个C++宏定义与枚举定义重复的编译错误
C++的开发效率低是众所周知的,原因比如有: 语言复杂度高 编译效率低 工具链不够完整高效(尤其是linux下) 另外一个恐怕是不少编译错误让人摸不着头脑,今天碰到一个,举个例子: #include ...
- oc中的枚举定义
typedef NS_ENUM(类型,枚举名){ 枚举名+值名, 枚举名+值名,}; 该方法定义的枚举,OC会自动把其转换成合适当前版本的枚举.如果枚举值可合并的话 NS_E ...
- 提高Java代码质量:使用枚举定义常量(转)
一.分析 常量的声明是每一个项目中不可或缺的,在Java1.5之前,我们只有两种方式的声明:类常量和接口常量.不过,在1.5版之后有了改进,即新增了一种常量声明方式,枚举常量.代码如下: enum ...
- C++中枚举定义运算符
由于枚举也是用户定义类型,所以是可以定义运算符, 如: enum Day {sun, mon, tue, wen, thu, fri, sat}; Day& operator++(Day&am ...
- iOS中枚举定义的三种方式
最简单的方式 typedef enum{ num1 = 0, num2 = 1, num3 = 2 }num; 同时我们还可以使用NS_ENUM的方式定义枚举 typedef NS_ENUM (NSI ...
- C# 给枚举定义DescriptionAttribute,把枚举转换为键值对
在C#中,枚举用来定状态值很方便,例如我定义一个叫做Season的枚举 public enum Season { Spring = 1, Summer = 2, Autumn = 3, Winter ...
随机推荐
- linux中init.d文件夹的说明
一.简单说明 /etc/init.d 是 /etc/rc.d/init.d 的软链接(soft link).可以通过 ll 命令查看. ls -ld /etc/init.d lrwxrwxrwx. r ...
- unity 主循环
在unity官方文档中看到这个图,感觉很有用,各事件的先后时机看得较清楚. 连接:http://docs.unity3d.com/Manual/ExecutionOrder.html
- 【转】获取scrollTop兼容各浏览器的方法,以及body和documentElement是啥?
1.各浏览器下 scrollTop的差异 IE6/7/8: 对于没有doctype声明的页面里可以使用 document.body.scrollTop 来获取 scrollTop高度 : 对于有do ...
- C++学习笔记16,C++11中的显式的默认构造函数以及显示删除默认构造函数
在早期的C++中.假设须要一些接受一些參数的构造函数,同一时候须要一个不接收不论什么參数的默认构造函数.就必须显示地编写空的默认构造函数.比如: //tc.h class A{ private: in ...
- CCDictionary(转)
#ifndef __CCDICTIONARY_H__ #define __CCDICTIONARY_H__ //需要哈希表的支持 #include "support/data_support ...
- CCRepeatForever和CCDelayTime
有限次执行一组动作和无限次执行一组动作 void ActionRotateJerk::onEnter() { ActionsDemo::onEnter(); centerSprites(); CCFi ...
- C++ 11 STL算法
STL算法部分主要由头文件<algorithm>,<numeric>,<functional>组成.要使用 STL中的算法函数必须包含头文件<algorith ...
- Ubuntu 12.04安装和设置SSH服务
OpenSSH 是 SSH (Secure SHell) 协议的免费开源实现.SSH协议族可以用来进行远程控制, 或在计算机之间传送文件.而实现此功能的传统方式,如telnet(终端仿真协议). rc ...
- js实现新闻条目滚动效果
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 统一处理jquery ajax请求过程中的异常错误信息的机制
当jQuery ajax向服务器发送请求,服务器发生异常,比如:400.403.404.500等异常,服务器将异常响应给客户端,此时的ajax可以获取异常信息并进行处理,但此时我们一般是跳转到与异常编 ...