UIview的基本使用
1.????正常創(chuàng)建一個視圖
????UIView *view = [[UIView alloc] initWithFrame:(CGRectMake(68, 13, 6, 6))]; (初始化)
????view.layer.masksToBounds=YES;(添加圓角)
????view.layer.cornerRadius=3;(添加圓角尺度)
????view.backgroundColor= [UIColorcolorWithHexString:YXZFF5353Color];(設置視圖顏色)
????[self.view addSubview: view];(添加到主視圖控制器)
自此一個帶有圓角的視圖view就創(chuàng)建好了
2. ? ?view其他屬性以及拓展
- (id)initWithFrame:(CGRect)frame; (初始化方法, 如果你想要自定義實現(xiàn), 可以創(chuàng)建并繼承uiview, 在重寫此方法就ojbk了)
? ? 2.1:?userInteractionEnabled 此屬性是可以控制用戶交互, 默認為YES(通常默認即可);
????2.2 :?tag(NSInteger)?控件的一個標記(父控件可以通過tag找到對應的子控件)默認為0;
????2.3:?layer(CALayer)?圖層(可以用來設置圓角效果\陰影效果);
????2.4:?frame(CGRect)?位置和尺寸(以父控件的左上角為坐標原點(0, 0));
? ? 2.5:?bounds(CGRect)?位置和尺寸(以自己的左上角為坐標原點(0, 0));
? ? 2.6:?center(CGPoint)?中點(以父控件的左上角為坐標原點(0, 0));
? ? 2.7:?transform(CGAffineTransform)?形變屬性(平移\縮放\旋轉);
????2.8:?multipleTouchEnabled(BOOL)?YES是支持多點觸摸 默認為NO;
? ? 2.9:?superview(UIView) 父控件(可以通過父控件找到父控件上的其他控件);
? ? 3.0:?subviews (NSSArray) 子控件集合 (所有新添加的子控件都顯示在最上面);
? ? 3.1:?window (UIWindow)?獲得當前控件所在的window(每個APP只能有一個window);
? ? 3.2:?clipsToBounds?YES 超出控件邊框范圍的內容都剪掉默認為YES;
? ? 3.3:?backgroundColor 設置背景顏色默認為nil;
? ? 3.4:?alpha?透明度(0.0~1.0);
? ? 3.5:?opaque 設置是否透明 YES: 不透明 NO: 透明 默認為YES;
????3.6:?hidden設置是否隱藏 YES: 隱藏 NO: 不隱藏 默認為NO;
layer(CALayer) 著重說一下view的這個屬性在創(chuàng)建的時候已經寫出來這個的使用方式
view.layer.masksToBounds =?YES;(添加圓角)
view.layer.cornerRadius = 3;(添加圓角尺度)
想要添加圓角這兩個屬性必須設置
3. UIView方法
? ? 3.1????- (void)removeFromSuperview;?從父控件中移除一個控件
? ? 3.2????- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index;?添加一個子控件(可以將子控件插入到subviews數(shù)組中index這個位置);
????3.3????- (void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2;交換subviews數(shù)組中所存放子控件的位置
? ? 3.4????- (void)addSubview:(UIView *)view;?添加一個子控件(通常顯示在最上面);
? ? 3.5????-(void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview;添加一個子控件view(被擋在siblingSubview的下面);
? ? 3.6????- (void)insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview;添加一個子控件view(蓋在siblingSubview的上面)
? ? 3.7????- (void)bringSubviewToFront:(UIView *)view;?將某個子控件拉到最上面(最頂部)來顯示
? ? 3.8????- (void)sendSubviewToBack:(UIView *)view;?將某個子控件拉到最下面(最底部)來顯示
? ? 3.9????- (BOOL)isDescendantOfView:(UIView *)view;?判斷view的子控件或者子控件的子控件(是否為view的后代) 默認返回YES;
? ? 4.0 ? ?- (UIView *)viewWithTag:(NSInteger)tag; (通過設置tag值來獲取對應的子控件);
? ? 4.1 ? ?- (void)layoutSubviews;系統(tǒng)自動調用(留給子類去實現(xiàn)),控件的frame發(fā)生改變的時候就會調用,一般在這里重寫布局子控件的位置和尺寸重寫了這個寫方法后,一定調用[super layoutSubviews];
- (void)didAddSubview:(UIView *)subview;
- (void)willRemoveSubview:(UIView *)subview;
- (void)willMoveToSuperview:(UIView *)newSuperview;
- (void)didMoveToSuperview;
- (void)willMoveToWindow:(UIWindow *)newWindow;
- (void)didMoveToWindow;?
系統(tǒng)自動調用(留給子類去實現(xiàn), 子類可以重寫)?
5. UIView動畫
+(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;