UIView的几个枚举定义

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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的几个枚举定义的主要内容,如果未能解决你的问题,请参考以下文章

C#编程开发的几个基础小知识

IEnumerable的几个简单用法

UIView(包括子类)的几个初始化时执行动作的时机

uiview的几个刷新的界面刷新的方法

java枚举类的几点疑惑

PropertyGrid目前的几个需求技术上无法解决