iOS UIView 一些属性方法总结

本文深入解析了UIView的基础概念,包括视图的位置几何属性、层次结构管理、渲染特性及动画实现方式。介绍了frame、bounds等关键属性,并展示了如何通过不同的方法添加、移除或调整子视图的位置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

UIView 是视图基类,以下这这类结构图可以看出view 常用UI空间都是这个类的子类








1 view 位置几何 UIViewGeometry
     常用的有 
     frame
     bounds 
     center 
     transform(默认是CGAffineTransformIdentity。可以做成动画)
     multipleTouchEnabled(当前视图是否接受多点触控事件,缺省值为NO)
     exclusiveTouch (当前视图是否接受单点触控,默认值是no)
     autoresizesSubviews(这个属性是决定当视图大小边界发生改变时,其子视图是否也跟着自动调整大小)
     autoresizingMask(简单的调整。默认是UIViewAutoresizingNone)
     
2: UIView层次结构
     superview(父视图)
     subviews(子视图)返回时数组
     window(窗口)
     - (void)removeFromSuperview;(从父视图上移除)
     - (void)insertSubview:(UIView *)view atIndex:(NSInteger)index;(插入一个视图在index处)
     - (void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2;(切换两个视图位置)
     - (void)addSubview:(UIView *)view;(添加视图)
     - (void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview;(添加到哪个视图之上)
     - (void)insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview;(添加到哪个个视图之下)
     - (void)bringSubviewToFront:(UIView *)view;(将子视图至前)
     - (void)sendSubviewToBack:(UIView *)view;(将子视图放到后面)
     - (void)didAddSubview:(UIView *)subview;()
     - (void)willRemoveSubview:(UIView *)subview;(将要移除子视图)
     - (nullable __kindof UIView *)viewWithTag:(NSInteger)tag;(根据tag值获取视图)
     - (void)setNeedsLayout;(强制布局)
     - (void)layoutIfNeeded;
3: UIViewRendering(UIView呈现)
      clipsToBounds(是的,内容和子视图省略视图的范围。默认是否定的。)
      alpha (透明度,默认值是一)
      hidden(是否隐藏视图,默认是不隐藏)
      tintColor (色调颜色,开始用于IOS7)
4:UIViewAnimation(视图动画)
     + (void)beginAnimations:(nullable NSString *)animationID context:(nullable void *)context;(UIViewRenderingadditional上下文信息传递给会启动/停止选择器。开始/提交可以嵌套)
     + (void)commitAnimations;开始动画
     
     + (void)setAnimationDelegate:(nullable id)delegate;(设置代理)
     + (void)setAnimationWillStartSelector:(nullable SEL)selector;                // default = NULL. -animationWillStart:(NSString *)animationID context:(void *)context
     + (void)setAnimationDidStopSelector:(nullable SEL)selector;                  // default = NULL. -animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
     + (void)setAnimationDuration:(NSTimeInterval)duration;              // default = 0.2
     + (void)setAnimationDelay:(NSTimeInterval)delay;                    // default = 0.0
     + (void)setAnimationStartDate:(NSDate *)startDate;
     
5:UIViewAnimationWithBlocks(动画块)
     常用的方法
     1 + (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(4_0);
     2 + (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); // delay = 0.0, options = 0
     
     */
    


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值