日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

UIView之常用方法

發布時間:2023/12/10 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 UIView之常用方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

UIView之常用方法

  • 將一個視圖添加為子視圖,并使之在最上面顯示
    -(void)addSubView:(UIView *)view;
  • 將指定子視圖移動到頂部
    -(void)bringSubViewToFront:(UIView *)view;
  • 將指定之視圖放到最下面
    -(void)sendSubViewToBack:(UIView *)view;
  • 將指定視圖添加到subviews數組的index位置
    -(void)insertSubview:(UIView *)view atIndex:(NSInteger)index;
  • 將指定視圖添加到指定子視圖下面
    -(void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview;
  • 將指定視圖添加到指定子視圖上面
    -(void)insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview;
  • 交換subviews數組中兩個位置的子視圖
    -(void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2;
  • 從父視圖中移除
    -(void)removeFromSuperview;
  • 根據tag值獲取對應的子孫控件
    -(UIView *)viewWithTag:(NSInteger)tag;
  • 將視圖中點從自己的坐標系轉換到指定的視圖坐標系中
    -(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;
  • 刷新視圖,調用后自動調用drawRect:(CGRect)rect
    -(void)setNeedsDisplay;

  • 繼承自UIResponder用于響應觸摸事件的方法
1.- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
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重寫,若需要對觸摸點到判斷(使用)那么重寫方法時,在方法體內首先獲取觸摸點:

1.UITouch *touch = [touches anyObject];
2.CGPoint point = [touch locationInView:self];

  • 動畫
1.// 首先需要設置動畫頭,告訴編譯器下面是動畫
2.[UIView beginAnimations:nil context:nil];
3.// 再設置動畫執行的配置、動畫
4.[UIView setAnimationDuration:0.5];
5.[UIView setAnimationRepeatCount:2];
6.[UIView setAnimationDelay:3.0];
7.// balabala需要執行的動畫
8. ................
9.// 最后提交動畫
10.[UIView commitAnimations];
  • 使用block設置動畫
    • 方法一
      +(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

轉載于:https://www.cnblogs.com/buakaw/p/5069287.html

總結

以上是生活随笔為你收集整理的UIView之常用方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。