UIview添加視圖


view常用屬性 
@property(nonatomic) CGAffineTransform transform;   // default is CGAffineTransformIdentity
//注釋:形變屬性(平移\縮放\旋轉(zhuǎn))
@property(nonatomic,getter=isMultipleTouchEnabled) BOOL multipleTouchEnabled;   
//注釋:YES:支持多點觸摸    默認是 NO
@property(nonatomic,readonly,retain)   CALayer  *layer
//注釋:圖層(可以用來設(shè)置圓角效果\陰影效果)
@property(nonatomic,getter=isUserInteractionEnabled) BOOL userInteractionEnabled;
//注釋:YES:能夠跟用戶進行交互   默認是YES
@property(nonatomic,readonly) UIView       *superview;
//注釋:父控件
@property(nonatomic,readonly,copy) NSArray *subviews;
//注釋:子控件(新添加的控件默認都在subviews數(shù)組的后面, 新添加的控件默認都顯示在最上面\最頂部)
@property(nonatomic,readonly) UIWindow     *window;
//注釋:獲得當前控件所在的window(window常為一個,但可以不止一個)
@property(nonatomic)                 BOOL              clipsToBounds;
//注釋:YES : 超出控件邊框范圍的內(nèi)容都剪掉
@property(nonatomic,copy)            UIColor          *backgroundColor; 
//注釋:背景色                       默認:nil
@property(nonatomic)                 CGFloat           alpha;       
//注意:透明度(0.0~1.0)         默認:1.0
@property(nonatomic,getter=isOpaque) BOOL              opaque;               
//注釋:YES:不透明  NO:透明   默認:YES
@property(nonatomic,getter=isHidden) BOOL              hidden;
//注釋:YES : 隱藏  NO : 顯示
@property(nonatomic)                 UIViewContentMode contentMode;              
//注釋:內(nèi)容模式     默認是UIViewContentModeScaleToFill

//在view上添加視圖
- (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)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2;
//移除視圖上所有視圖
- (void)removeFromSuperview;

// 將像素point由point所在視圖轉(zhuǎn)換到目標視圖view中,返回在目標視圖view中的像素值
- (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view;
// 將像素point從view中轉(zhuǎn)換到當前視圖中,返回在當前視圖中的像素值
- (CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view;
// 將rect由rect所在視圖轉(zhuǎn)換到目標視圖view中,返回在目標視圖view中的rect
- (CGRect)convertRect:(CGRect)rect toView:(UIView *)view;
// 將rect從view中轉(zhuǎn)換到當前視圖中,返回在當前視圖中的rect
- (CGRect)convertRect:(CGRect)rect fromView:(UIView *)view;
// controllerA 中有一個UITableView, UITableView里有多行UITableVieCell,cell上放有一個button
// 在controllerA中實現(xiàn):
CGRect rc = [cell convertRect:cell.btn.frame toView:self.view];
或
CGRect rc = [self.view convertRect:cell.btn.frame fromView:cell];
// 此rc為btn在controllerA中的rect
或當已知btn時:
CGRect rc = [btn.superview convertRect:btn.frame toView:self.view];
或
CGRect rc = [self.view convertRect:btn.frame fromView:btn.superview];
系統(tǒng)自動調(diào)用
//當加入視圖完成后
- (void)didAddSubview:(UIView *)subview;
//當視圖移除完成后
- (void)willRemoveSubview:(UIView *)subview;
//在刪除視圖之后調(diào)用 
- (void)willMoveToSuperview:(UIView *)newSuperview;

- (void)didMoveToSuperview;
//當視圖移動到新的WINDOW后調(diào)用 
- (void)willMoveToWindow:(UIWindow *)newWindow;

- (void)didMoveToWindow;

//判斷是不是view的子控件或者子控件的子控件(是否為view的子類) 
- (BOOL)isDescendantOfView:(UIView *)view; 
//通過tag獲得對應(yīng)的子控件(也可以或者子控件的子控件) 
- (UIView *)viewWithTag:(NSInteger)tag; 
//例如一個視圖淡出屏幕,另外一個視圖出現(xiàn)的代碼: 
[UIView animateWithDuration:1.0 animations:^{
       
}];
completion為動畫執(zhí)行完畢以后執(zhí)行的代碼塊 
options為動畫執(zhí)行的選項。可以參考這里 
delay為動畫開始執(zhí)行前等待的時間 
如何實現(xiàn)連續(xù)的動畫? 
可以在completion代碼塊中添加動畫。 
  [UIView animateWithDuration:2.0  animations:^{
                     oldImageView.alpha = 0.0;
                     newImageView.alpha = 1.0;
                     //imageView.center = CGPointMake(500.0, 512.0);
                 }completion:^(BOOL finished){
   [UIView animateWithDuration:4.0  animations:^{
               newImageView.center = CGPointMake(500.0, 512.0);
   }];
 }];

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容