美文网首页
UIView的一些常见属性

UIView的一些常见属性

作者: 浪漫紫薇星 | 来源:发表于2016-02-01 11:06 被阅读1140次

UIView

//继承自UIResponder,拥有touches方法

@interface UIView : UIResponder

/**

*  通过一个frame来初始化一个UI控件

*/

- (id)initWithFrame:(CGRect)frame;

// YES:能够跟用户进行交互

@property(nonatomic,getter=isUserInteractionEnabled) BOOL userInteractionEnabled;  // default is YES

// 控件的一个标记(父控件可以通过tag找到对应的子控件)

@property(nonatomic)                                 NSInteger tag;                // default is 0

// 图层(可以用来设置圆角效果\阴影效果)

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

@end

@interface UIView(UIViewGeometry)

// 位置和尺寸(以父控件的左上角为坐标原点(0, 0))

@property(nonatomic) CGRect            frame;

// 位置和尺寸(以自己的左上角为坐标原点(0, 0))

@property(nonatomic) CGRect            bounds;

// 中点(以父控件的左上角为坐标原点(0, 0))

@property(nonatomic) CGPoint           center;

// 形变属性(平移\缩放\旋转)

@property(nonatomic) CGAffineTransform transform;   // default is CGAffineTransformIdentity

// YES:支持多点触摸

@property(nonatomic,getter=isMultipleTouchEnabled) BOOL multipleTouchEnabled;   // default is NO

@end

@interface UIView(UIViewHierarchy)

// 父控件

@property(nonatomic,readonly) UIView       *superview;

// 子控件(新添加的控件默认都在subviews数组的后面, 新添加的控件默认都显示在最上面\最顶部)

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

// 获得当前控件所在的window

@property(nonatomic,readonly) UIWindow     *window;

// 从父控件中移除一个控件

- (void)removeFromSuperview;

// 添加一个子控件(可以将子控件插入到subviews数组中index这个位置)

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

// 交换subviews数组中所存放子控件的位置

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

// 添加一个子控件(新添加的控件默认都在subviews数组的后面, 新添加的控件默认都显示在最上面\最顶部)

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

// 添加一个子控件view(被挡在siblingSubview的下面)

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

// 添加一个子控件view(盖在siblingSubview的上面)

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

// 将某个子控件拉到最上面(最顶部)来显示

- (void)bringSubviewToFront:(UIView *)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;

/**系统自动调用**/

// 是不是view的子控件或者子控件的子控件(是否为view的后代)

- (BOOL)isDescendantOfView:(UIView *)view;  // returns YES for self.

// 通过tag获得对应的子控件(也可以或者子控件的子控件)

- (UIView *)viewWithTag:(NSInteger)tag;     // recursive search. includes self

/**系统自动调用(留给子类去实现)**/

// 控件的frame发生改变的时候就会调用,一般在这里重写布局子控件的位置和尺寸

// 重写了这个写方法后,一定调用[super layoutSubviews];

- (void)layoutSubviews;

@end

@interface UIView(UIViewRendering)

// YES : 超出控件边框范围的内容都剪掉

@property(nonatomic)                 BOOL              clipsToBounds;

// 背景色

@property(nonatomic,copy)            UIColor          *backgroundColor; // default is nil

// 透明度(0.0~1.0)

@property(nonatomic)                 CGFloat           alpha;                      // default is 1.0

// YES:不透明  NO:透明

@property(nonatomic,getter=isOpaque) BOOL              opaque;                     // default is YES

// YES : 隐藏  NO : 显示

@property(nonatomic,getter=isHidden) BOOL              hidden;

// 内容模式

@property(nonatomic)                 UIViewContentMode contentMode;                // default is UIViewContentModeScaleToFill

@end

//设置属性改变时的动画

@interface UIView(UIViewAnimationWithBlocks)

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

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion;

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations;

+ (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;

@end。

相关文章

  • iOS-UIVIew

    UIView的常见属性 •@property(nonatomic,readonly) UIView *superv...

  • UIView的一些常见属性

    UIView //继承自UIResponder,拥有touches方法 @interfaceUIView:UIRe...

  • UI基础2

    UIView常见属性和方法 UIView(UIViewGeometry):几何 frame:边框,CGSize,C...

  • UIView的常见属性

    UIView的常见属性 NSArray *subviews所有的子控件数组元素的顺序决定着子控件的显示层级顺序(下...

  • UIView的常见属性

  • UIView的常见属性

    @property(nonatomic,readonly) UIView *superview; // 获得自己的...

  • UIView的基本使用

    UIView UI控件的基类,拥有尺寸、位置、背景色等基本属性。其他的控件继承自UIVIew。 UIView的常见...

  • iOS动画之基于UIView的仿射形变动画(一)

    UIView动画 一、简介设置UIView形变动画有两种常见用到的属性,.frame,.transform,所以有...

  • IOS动画之UIView动画

    UIView之属性动画 UIKit直接将动画集成刀UIView类中,当内被的一些属性发生改变时,UIView可以为...

  • UI基础

    第一节 1.UI控件中拖线属性或方法常见错误 2.UIView的常见属性 (void)addSubview:(UI...

网友评论

      本文标题:UIView的一些常见属性

      本文链接:https://www.haomeiwen.com/subject/sleskttx.html