UIView的常用方法

UIView : UIResponder <NSCoding, UIAppearance, UIAppearanceContainer, UIDynamicItem, UITraitEnvironment, UICoordinateSpace>

+ (Class)layerClass; 

- (instancetype)initWithFrame:(CGRect)frame; 

//是否可点击

@property(nonatomic,getter=isUserInteractionEnabled) BOOL userInteractionEnabled;  

 @property(nonatomic,readonly,retain)                 CALayer  *layer; 

 

@interface UIView(UIViewGeometry)

//仿射变化

@property(nonatomic) CGAffineTransform transform; 

@property(nonatomic) CGFloat           contentScaleFactor NS_AVAILABLE_IOS(4_0);

@property(nonatomic,getter=isMultipleTouchEnabled) BOOL multipleTouchEnabled;

@property(nonatomic,getter=isExclusiveTouch) BOOL       exclusiveTouch; 

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event; 

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event; 

 //将像素point由point所在视图转换到目标视图view中,返回在目标视图view中的像素值

- (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view;

// 将目标点得位置

- (CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view;

- (CGRect)convertRect:(CGRect)rect toView:(UIView *)view;

- (CGRect)convertRect:(CGRect)rect fromView:(UIView *)view;

//

如果视图的 autoresizesSubviews  属性声明被设置为YES,则其子视图会根据
autoresizingMask  属性的值自动进行尺寸调整。否则,应用程序就必须通过重载layoutSubviews  方法来提供自己的实现。

 

@property(nonatomic) BOOL               autoresizesSubviews;

 

@property(nonatomic) UIViewAutoresizing autoresizingMask; 

//sizeThatFits传入的参数是当前的size,返回一个适合的size

- (CGSize)sizeThatFits:(CGSize)size;   

//得到最适合当前字数的尺寸

- (void)sizeToFit;  

@interface UIView(UIViewHierarchy)

 //父视图

@property(nonatomic,readonly) UIView       *superview; 

//子视图集合

@property(nonatomic,readonly,copy) NSArray *subviews;

//窗口

@property(nonatomic,readonly) UIWindow     *window;

 //从父视图上移除

- (void)removeFromSuperview;

//在视图层级index位置插入视图

- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index;

//交换视图

- (void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2;

 //添加子视图

- (void)addSubview:(UIView *)view;

//在siblingSubview 视图下面插入视图view

- (void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview;

//在siblingSubview上面插入视图view

- (void)insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview;

 //将视图移动到view 上层

- (void)bringSubviewToFront:(UIView *)view;

//将视图移动到view 下层

- (void)sendSubviewToBack:(UIView *)view;

- (void)didAddSubview:(UIView *)subview;

- (void)willRemoveSubview:(UIView *)subview;

- (void)willMoveToSuperview:(UIView *)newSuperview;

- (void)didMoveToSuperview;

- (void)willMoveToWindow:(UIWindow *)newWindow;

- (void)didMoveToWindow;

//返回一个布尔值指出接收者是否是给定视图的子视图或者指向那个视图 

- (BOOL)isDescendantOfView:(UIView *)view

 

- (void)setNeedsLayout;

- (void)layoutIfNeeded;

- (void)layoutSubviews; 


http://blog.csdn.net/zhenweicao/article/details/8113734

关于ios中的setNeedsDisplay和setNeedsLayout


//layoutMargins返回一组从视图的范围边缘的insets,表示默认间距布置的内容。 设置间距

@property (nonatomic) UIEdgeInsets layoutMargins NS_AVAILABLE_IOS(8_0);

@property (nonatomic) BOOL preservesSuperviewLayoutMargins NS_AVAILABLE_IOS(8_0);

- (void)layoutMarginsDidChange NS_AVAILABLE_IOS(8_0);

 

@interface UIView(UIViewRendering)

 

- (void)drawRect:(CGRect)rect;

 - (void)setNeedsDisplay;

- (void)setNeedsDisplayInRect:(CGRect)rect;

 //决定了子视图的显示范围。具体的说,就是当取值为YES时,剪裁超出父视图范围的子视图部分;当取值为NO时,不剪裁子视图(超出部分继续显示,例如在scrollview中。。。)。默认值为NO

@property(nonatomic)                 BOOL              clipsToBounds; 

//UIView每次重会之前,清除掉上次的内容,系统默认就是YES,这个特性不是IOS7才有的

@property(nonatomic)                 BOOL              clearsContextBeforeDrawing; 

@property(nonatomic)                 UIViewContentMode contentMode; 


typedef NS_ENUM(NSInteger, UIViewContentMode) {

    UIViewContentModeScaleToFill,

    UIViewContentModeScaleAspectFit,      // contents scaled to fit with fixed aspect. remainder is transparent

    UIViewContentModeScaleAspectFill,     // contents scaled to fill with fixed aspect. some portion of content may be clipped.

    UIViewContentModeRedraw,              // redraw on bounds change (calls -setNeedsDisplay)

    UIViewContentModeCenter,              // contents remain same size. positioned adjusted.

    UIViewContentModeTop,

    UIViewContentModeBottom,

    UIViewContentModeLeft,

    UIViewContentModeRight,

    UIViewContentModeTopLeft,

    UIViewContentModeTopRight,

    UIViewContentModeBottomLeft,

    UIViewContentModeBottomRight,

};

 

 


 

@property(nonatomic,retain)          UIView           *maskView NS_AVAILABLE_IOS(8_0);

//色调 

@property(nonatomic,retain) UIColor *tintColor NS_AVAILABLE_IOS(7_0);

 //色调调整模式,开始用于IOS7

@property(nonatomic) UIViewTintAdjustmentMode tintAdjustmentMode NS_AVAILABLE_IOS(7_0);


@interface UIView(UIViewAnimation)

 //开始动画,

+ (void)beginAnimations:(NSString *)animationID context:(void *)context

 + (void)commitAnimations;

+ (void)setAnimationDelegate:(id)delegate;                          // default = nil

+ (void)setAnimationWillStartSelector:(SEL)selector; 

//当动画结束时,执行delegate对象的selector,并且把beginAnimations:context:中传入的参数传进selector

+ (void)setAnimationDidStopSelector:(SEL)selector;

+ (void)setAnimationDuration:(NSTimeInterval)duration;              // default = 0.2

+ (void)setAnimationDelay:(NSTimeInterval)delay;                    // default = 0.0

//画的开始时间,默认为now

+ (void)setAnimationStartDate:(NSDate *)startDate;

//设置动画曲线

+ (void)setAnimationCurve:(UIViewAnimationCurve)curve;  


typedef NS_ENUM(NSInteger, UIViewAnimationCurve) {

    UIViewAnimationCurveEaseInOut,         // slow at beginning and end

    UIViewAnimationCurveEaseIn,            // slow at beginning

    UIViewAnimationCurveEaseOut,           // slow at end

    UIViewAnimationCurveLinear

};


 //重复次数

+ (void)setAnimationRepeatCount:(float)repeatCount;  

//如果设置为YES,代表动画每次重复执行的效果会跟上一次相反

+ (void)setAnimationRepeatAutoreverses:(BOOL)repeatAutoreverses;

 

 


 

@interface UIView(UIViewAnimationWithBlocks)

 

+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0);

 /*

[UIView transitionWithView:self.view duration:1 options: UIViewAnimationOptionCurveEaseInOut animations:^{

        _view2.alpha = 0 ;

    } completion:^(BOOL finished) {

        

    }];

 

*/

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); // delay = 0.0, options = 0

 

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations NS_AVAILABLE_IOS(4_0); // delay = 0.0, options = 0, completion = NULL

 

 

+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay usingSpringWithDamping:(CGFloat)dampingRatio initialSpringVelocity:(CGFloat)velocity options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(7_0);

 

/*转场动画 

duration:动画的持续时间

view:需要进行转场动画的视图

options:转场动画的类型

animations:将改变视图属性的代码放在这个block中

completion:动画结束后,会自动调用这个block

*/

+ (void)transitionWithView:(UIView *)view duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0);

/*转场动画

http://www.tuicool.com/articles/QveUvy

只需要在当前视图加载1个view ,

方法调用完毕后,相当于执行了下面两句代码:

// 添加toView到父视图

[fromView.superview addSubview:toView]; 

// 把fromView从父视图中移除

[fromView.superview removeFromSuperview];

 */

+ (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); // toView added to fromView.superview, fromView removed from its superview

 //在一组视图上执行指定的系统动画,并可以并行自定义的动画

+ (void)performSystemAnimation:(UISystemAnimation)animation onViews:(NSArray *)views options:(UIViewAnimationOptions)options animations:(void (^)(void))parallelAnimations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(7_0);

 


 

@interface UIView (UIViewKeyframeAnimations)

 

+ (void)animateKeyframesWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewKeyframeAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(7_0);

+ (void)addKeyframeWithRelativeStartTime:(double)frameStartTime relativeDuration:(double)frameDuration animations:(void (^)(void))animations NS_AVAILABLE_IOS(7_0); 

 

 

 

 

 

 

 

 

 

原文地址:https://www.cnblogs.com/qzp2014/p/4269716.html