UIView之常用方法
生活随笔
收集整理的這篇文章主要介紹了
UIView之常用方法
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
UIView之常用方法
- 將一個(gè)視圖添加為子視圖,并使之在最上面顯示
-(void)addSubView:(UIView *)view; - 將指定子視圖移動(dòng)到頂部
-(void)bringSubViewToFront:(UIView *)view; - 將指定之視圖放到最下面
-(void)sendSubViewToBack:(UIView *)view; - 將指定視圖添加到subviews數(shù)組的index位置
-(void)insertSubview:(UIView *)view atIndex:(NSInteger)index; - 將指定視圖添加到指定子視圖下面
-(void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview; - 將指定視圖添加到指定子視圖上面
-(void)insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview; - 交換subviews數(shù)組中兩個(gè)位置的子視圖
-(void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2; - 從父視圖中移除
-(void)removeFromSuperview; - 根據(jù)tag值獲取對(duì)應(yīng)的子孫控件
-(UIView *)viewWithTag:(NSInteger)tag; - 將視圖中點(diǎn)從自己的坐標(biāo)系轉(zhuǎn)換到指定的視圖坐標(biāo)系中
-(CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view; - 將指定視圖中坐標(biāo)系內(nèi)的某點(diǎn)轉(zhuǎn)換到自己的坐標(biāo)系中
-(CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view; - 將視圖中矩形區(qū)域從自己的坐標(biāo)系轉(zhuǎn)換到指定的視圖坐標(biāo)系中
-(CGRect)convertRect:(CGRect)rect toView:(UIView *)view; - 將指定視圖中坐標(biāo)系內(nèi)的矩形區(qū)域轉(zhuǎn)換到自己的坐標(biāo)系中
-(CGRect)convertRect:(CGRect)rect fromView:(UIView *)view; - 刷新視圖,調(diào)用后自動(dòng)調(diào)用drawRect:(CGRect)rect
-(void)setNeedsDisplay;
- 繼承自UIResponder用于響應(yīng)觸摸事件的方法
2.- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
3.- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
4.- (void)touchesCancelled:(nullable NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
以上方法需要自定義view重寫,若需要對(duì)觸摸點(diǎn)到判斷(使用)那么重寫方法時(shí),在方法體內(nèi)首先獲取觸摸點(diǎn):
1.UITouch *touch = [touches anyObject];2.CGPoint point = [touch locationInView:self];
- 動(dòng)畫
2.[UIView beginAnimations:nil context:nil];
3.// 再設(shè)置動(dòng)畫執(zhí)行的配置、動(dòng)畫
4.[UIView setAnimationDuration:0.5];
5.[UIView setAnimationRepeatCount:2];
6.[UIView setAnimationDelay:3.0];
7.// balabala需要執(zhí)行的動(dòng)畫
8. ................
9.// 最后提交動(dòng)畫
10.[UIView commitAnimations];
- 使用block設(shè)置動(dòng)畫
- 方法一
+(void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations; - 方法二
+(void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^ __nullable)(BOOL finished))completion - 方法三
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^ __nullable)(BOOL finished))completion
- 方法一
轉(zhuǎn)載于:https://www.cnblogs.com/buakaw/p/5069287.html
總結(jié)
以上是生活随笔為你收集整理的UIView之常用方法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: webstorm 破解的方法
- 下一篇: Chrome浏览器护眼插件