• UIView


    1.+ (Class)layerClass; 

    默认的CALayer

    2.@property(nonatomic,getter=isUserInteractionEnabled) BOOL userInteractionEnabled; 

    是否响应事件

    3.@property(nonatomic)                                 NSInteger tag; 

    标签,默认为0

    4.@property(nonatomic,readonly,strong)                 CALayer  *layer; 

    和图形相关

    UIView(UIViewGeometry)

    1.@property(nonatomic) CGRect            frame;
    // use bounds/center and not frame if non-identity transform. if bounds dimension is odd, center may be have fractional part
    @property(nonatomic) CGRect            bounds;      // default bounds is zero origin, frame size. animatable
    @property(nonatomic) CGPoint           center;      // center is center of frame. animatable
    @property(nonatomic) CGAffineTransform transform;   // default is CGAffineTransformIdentity. animatable
    @property(nonatomic) CGFloat           contentScaleFactor NS_AVAILABLE_IOS(4_0);

    基本属性

    2.@property(nonatomic,getter=isMultipleTouchEnabled) BOOL multipleTouchEnabled __TVOS_PROHIBITED;   // default is NO

    多点触碰

    3.@property(nonatomic,getter=isExclusiveTouch) BOOL       exclusiveTouch __TVOS_PROHIBITED;         // default is NO

    可以达到同一界面上多个控件接受事件时的排他性,从而避免一些问题。也就是说避免在一个界面上同时点击多个button。

    4.- (nullable UIView *)hitTest:(CGPoint)point withEvent:(nullable UIEvent *)event; 

    OS系统检测到手指触摸(Touch)操作时会将其放入当前活动Application的事件队列,UIApplication会从事件队列中取出触摸事件并传递给key window(当前接收用户事件的窗口)处理,window对象首先会使用hitTest:withEvent:方法寻找此次Touch操作初始点所在的视图(View),即需要将触摸事件传递给其处理的视图,称之为hit-test view。

    window对象会在首先在view hierarchy的顶级view上调用hitTest:withEvent:,此方法会在视图层级结构中的每个视图上调用pointInside:withEvent:,如果pointInside:withEvent:返回YES,则继续逐级调用,直到找到touch操作发生的位置,这个视图也就是hit-test view。

    hitTest:withEvent:方法的处理流程如下:

    1. 首先调用当前视图的pointInside:withEvent:方法判断触摸点是否在当前视图内;
    2. 若返回NO,则hitTest:withEvent:返回nil;
    3. 若返回YES,则向当前视图的所有子视图(subviews)发送hitTest:withEvent:消息,所有子视图的遍历顺序是从top到bottom,即从subviews数组的末尾向前遍历,直到有子视图返回非空对象或者全部子视图遍历完毕;
    4. 若第一次有子视图返回非空对象,则hitTest:withEvent:方法返回此对象,处理结束;
    5. 如所有子视图都返回非,则hitTest:withEvent:方法返回自身(self)。

    hitTest:withEvent:方法忽略隐藏(hidden=YES)的视图,禁止用户操作(userInteractionEnabled=YES)的视图,以及alpha级别小于0.01(alpha<0.01)的视图。如果一个子视图的区域超过父视图的bound区域(父视图的clipsToBounds 属性为NO,这样超过父视图bound区域的子视图内容也会显示),那么正常情况下对子视图在父视图之外区域的触摸操作不会被识别,因为父视图的pointInside:withEvent:方法会返回NO,这样就不会继续向下遍历子视图了。当然,也可以重写pointInside:withEvent:方法来处理这种情况。

    对于每个触摸操作都会有一个UITouch对象,UITouch对象用来表示一个触摸操作,即一个手指在屏幕上按下、移动、离开的整个过程。UITouch对象在触摸操作的过程中在不断变化,所以在使用UITouch对象时,不能直接retain,而需要使用其他手段存储UITouch的内部信息。UITouch对象有一个view属性,表示此触摸操作初始发生所在的视图,即上面检测到的hit-test view,此属性在UITouch的生命周期不再改变,即使触摸操作后续移动到其他视图之上。

    5.- (BOOL)pointInside:(CGPoint)point withEvent:(nullable UIEvent *)event;   // default returns YES if point is in bounds

    这个函数的用处是判断当前的点击或者触摸事件的点是否在当前的view中它被hitTest:withEvent:调用

    6.// 将像素point由point所在视图转换到目标视图view中,返回在目标视图view中的像素值  
    - (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view;  
    // 将像素point从view中转换到当前视图中,返回在当前视图中的像素值  
    - (CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view;  
      
    // 将rect由rect所在视图转换到目标视图view中,返回在目标视图view中的rect  
    - (CGRect)convertRect:(CGRect)rect toView:(UIView *)view;  
    // 将rect从view中转换到当前视图中,返回在当前视图中的rect  
    - (CGRect)convertRect:(CGRect)rect fromView:(UIView *)view;  
    7.autoresizingMask
    enum {
       UIViewAutoresizingNone                 = 0,
       UIViewAutoresizingFlexibleLeftMargin   = 1 << 0,
       UIViewAutoresizingFlexibleWidth        = 1 << 1,
       UIViewAutoresizingFlexibleRightMargin  = 1 << 2,
       UIViewAutoresizingFlexibleTopMargin    = 1 << 3,
       UIViewAutoresizingFlexibleHeight       = 1 << 4,
       UIViewAutoresizingFlexibleBottomMargin = 1 << 5
    };

    UIViewAutoresizingNone就是不自动调整。
    UIViewAutoresizingFlexibleLeftMargin 自动调整与superView左边的距离,保证与superView右边的距离不变。
    UIViewAutoresizingFlexibleRightMargin 自动调整与superView的右边距离,保证与superView左边的距离不变。
    UIViewAutoresizingFlexibleTopMargin 自动调整与superView顶部的距离,保证与superView底部的距离不变。
    UIViewAutoresizingFlexibleBottomMargin 自动调整与superView底部的距离,也就是说,与superView顶部的距离不变。
    UIViewAutoresizingFlexibleWidth 自动调整自己的宽度,保证与superView左边和右边的距离不变。
    UIViewAutoresizingFlexibleHeight 自动调整自己的高度,保证与superView顶部和底部的距离不变。
    UIViewAutoresizingFlexibleLeftMargin  |UIViewAutoresizingFlexibleRightMargin 自动调整与superView左边的距离,保证与左边的距离和右边的距离和原来距左边和右边的距离的比例不变。比如原来距离为20,30,调整后的距离应为68,102,即68/20=102/30。

    8.- (CGSize)sizeThatFits:(CGSize)size;     // return 'best' size to fit given size. does not actually resize view. Default is return existing view size
    - (void)sizeToFit; 

    得到最适合当前字数的尺寸,设置尺寸

    UIView(UIViewHierarchy)

    1.@property(nullable, nonatomic,readonly) UIView       *superview;
    @property(nonatomic,readonly,copy) NSArray<__kindof UIView *> *subviews;
    @property(nullable, nonatomic,readonly) UIWindow     *window;

    父视图,子视图,window

    2.//重父视图中移除
    - (void)removeFromSuperview;
    //插入视图
    - (void)insertSubview:(UIView *)view atIndex:(NSInteger)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;
    
    //通知接收者父视图已经改变(nil是允许的)
    - (void)willMoveToSuperview:(nullable UIView *)newSuperview;
    //父视图已经改变
    - (void)didMoveToSuperview;
    //通知窗口已经改变
    - (void)willMoveToWindow:(nullable UIWindow *)newWindow;
    //窗口已经改变
    - (void)didMoveToWindow;
    3.- (BOOL)isDescendantOfView:(UIView *)view;  // returns YES for self.

    是不是view的子控件或者子控件的子控件(是否为view的后代)

    4.- (nullable __kindof UIView *)viewWithTag:(NSInteger)tag;

    通过tag获得对应的子控件(也可以或者子控件的子控件)

    5.- (void)setNeedsLayout;
    - (void)layoutIfNeeded;
    
    - (void)layoutSubviews;    // override point. called by layoutIfNeeded automatically. As of iOS 6.0, when constraints-based layout is used the base implementation applies the constraints-based layout, otherwise it does nothing.

    layoutSubviews在以下情况下会被调用:

    1、init初始化不会触发layoutSubviews

       但是是用initWithFrame 进行初始化时,当rect的值不为CGRectZero时,也会触发

    2、addSubview会触发layoutSubviews

    3、设置view的Frame会触发layoutSubviews,当然前提是frame的值设置前后发生了变化

    4、滚动一个UIScrollView会触发layoutSubviews

    5、旋转Screen会触发父UIView上的layoutSubviews事件

    6、改变一个UIView大小的时候也会触发父UIView上的layoutSubviews事件

    在苹果的官方文档中强调:

          You should override this method only if the autoresizing behaviors of the subviews do not offer the behavior you want.

    layoutSubviews, 当我们在某个类的内部调整子视图位置时,需要调用。

    反过来的意思就是说:如果你想要在外部设置subviews的位置,就不要重写。

    刷新子对象布局
    -layoutSubviews方法:这个方法,默认没有做任何事情,需要子类进行重写
    -setNeedsLayout方法: 标记为需要重新布局,异步调用layoutIfNeeded刷新布局,不立即刷新,但layoutSubviews一定会被调用
    -layoutIfNeeded方法:如果,有需要刷新的标记,立即调用layoutSubviews进行布局(如果没有标记,不会调用layoutSubviews)

    6.@property (nonatomic) UIEdgeInsets layoutMargins NS_AVAILABLE_IOS(8_0);

    内容离四周的间距

    UIView(UIViewRendering)

    1.-drawRect:(CGRect)rect方法:重写此方法,执行重绘任务
    -setNeedsDisplay方法:标记为需要重绘,异步调用drawRect
    -setNeedsDisplayInRect:(CGRect)invalidRect方法:标记为需要局部重绘
    2.//超出父视图不显示
    @property(nonatomic)                 BOOL              clipsToBounds;  
    //背景色
    @property(nullable, nonatomic,copy)            UIColor          *backgroundColor UI_APPEARANCE_SELECTOR;
    //透明度
    @property(nonatomic)                 CGFloat           alpha; 
    //是否不透明
    @property(nonatomic,getter=isOpaque) BOOL              opaque; 
    // 在绘制前清除内容
    @property(nonatomic)                 BOOL              clearsContextBeforeDrawing;
    //隐藏视图
    @property(nonatomic,getter=isHidden) BOOL              hidden;    
    //显示内容的样式
    @property(nonatomic)                 UIViewContentMode contentMode;                // default is UIViewContentModeScaleToFill
    //主题颜色
    @property(null_resettable, nonatomic, strong) UIColor *tintColor NS_AVAILABLE_IOS(7_0);
    //颜色渲染,变暗等
    @property(nonatomic) UIViewTintAdjustmentMode tintAdjustmentMode NS_AVAILABLE_IOS(7_0);
    //-tintColorDidChange消息发送给适当的视图的子视图时tintColor改变由客户机代码或视图的子视图在视图层次的tintColor时隐式地改变它的父视图或tintAdjustmentMode变化。
    - (void)tintColorDidChange NS_AVAILABLE_IOS(7_0);

    UIView(UIViewAnimation)

    1.+ (void)beginAnimations:(nullable NSString *)animationID context:(nullable void *)context;

    用来,表示动画的开始。

    animationID:作为动画的标识

    context:自定义的一些动画数据,这些数据将发送给动画的代理方法:setAnimationWillStartSelector:方法和setAnimationDidStopSelector:方法。

    这个,参数,通常为nil。我们可以直接设置为nil。

    这里,我们使用UIGraphicsGetCurrentContext();因为此方法默认也会返回nil。

    + (void)beginAnimations:(nullable NSString *)animationID context:(nullable void *)context;  // additional context info passed to will start/did stop selectors. begin/commit can be nested
    + (void)commitAnimations;                                                 // starts up any animations when the top level animation is commited
    
    // no getters. if called outside animation block, these setters have no effect.
    + (void)setAnimationDelegate:(nullable id)delegate;                          // default = nil
    + (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;                  // default = now ([NSDate date])
    + (void)setAnimationCurve:(UIViewAnimationCurve)curve;              // default = UIViewAnimationCurveEaseInOut
    + (void)setAnimationRepeatCount:(float)repeatCount;                 // default = 0.0.  May be fractional
    + (void)setAnimationRepeatAutoreverses:(BOOL)repeatAutoreverses;    // default = NO. used if repeat count is non-zero
    + (void)setAnimationBeginsFromCurrentState:(BOOL)fromCurrentState;  // default = NO. If YES, the current view position is always used for new animations -- allowing animations to "pile up" on each other. Otherwise, the last end state is used for the animation (the default).
    
    + (void)setAnimationTransition:(UIViewAnimationTransition)transition forView:(UIView *)view cache:(BOOL)cache;  // current limitation - only one per begin/commit block
    
    + (void)setAnimationsEnabled:(BOOL)enabled;                         // ignore any attribute changes while set.
    + (BOOL)areAnimationsEnabled;
    + (void)performWithoutAnimation:(void (^)(void))actionsWithoutAnimation NS_AVAILABLE_IOS(7_0);
    
    + (NSTimeInterval)inheritedAnimationDuration NS_AVAILABLE_IOS(9_0);

    由于现在一般用block就不多研究这个了

    UIView(UIViewAnimationWithBlocks)

    + (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);
    
    + (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); // delay = 0.0, options = 0
    
    + (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations NS_AVAILABLE_IOS(4_0); // delay = 0.0, options = 0, completion = NULL
    
    /* Performs `animations` using a timing curve described by the motion of a spring. When `dampingRatio` is 1, the animation will smoothly decelerate to its final model values without oscillating. Damping ratios less than 1 will oscillate more and more before coming to a complete stop. You can use the initial spring velocity to specify how fast the object at the end of the simulated spring was moving before it was attached. It's a unit coordinate system, where 1 is defined as travelling the total animation distance in a second. So if you're changing an object's position by 200pt in this animation, and you want the animation to behave as if the object was moving at 100pt/s before the animation started, you'd pass 0.5. You'll typically want to pass 0 for the velocity. */ 
    + (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay usingSpringWithDamping:(CGFloat)dampingRatio initialSpringVelocity:(CGFloat)velocity options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(7_0);
    
    1.+ (void)transitionWithView:(UIView *)view duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^ __nullable)(void))animations completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(4_0);
    
    + (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); // toView added to fromView.superview, fromView removed from its superview
    
    /* Performs the requested system-provided animation on one or more views. Specify addtional animations in the parallelAnimations block. These additional animations will run alongside the system animation with the same timing and duration that the system animation defines/inherits. Additional animations should not modify properties of the view on which the system animation is being performed. Not all system animations honor all available options.
     */
    + (void)performSystemAnimation:(UISystemAnimation)animation onViews:(NSArray<__kindof UIView *> *)views options:(UIViewAnimationOptions)options animations:(void (^ __nullable)(void))parallelAnimations completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(7_0);

    UIView (UIViewKeyframeAnimations)

    1.+ (void)animateKeyframesWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewKeyframeAnimationOptions)options animations:(void (^)(void))animations completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(7_0);
    + (void)addKeyframeWithRelativeStartTime:(double)frameStartTime relativeDuration:(double)frameDuration animations:(void (^)(void))animations NS_AVAILABLE_IOS(7_0); // start time and duration are values between 0.0 and 1.0 specifying time and duration relative to the overall time of the keyframe animation

    UIView (UIViewGestureRecognizers)

    1.//手势识别器列表
    @property(nullable, nonatomic,copy) NSArray<__kindof UIGestureRecognizer *> *gestureRecognizers NS_AVAILABLE_IOS(3_2);
    
    //添加手势识别器
    - (void)addGestureRecognizer:(UIGestureRecognizer*)gestureRecognizer NS_AVAILABLE_IOS(3_2);
    //移除手势识别器
    - (void)removeGestureRecognizer:(UIGestureRecognizer*)gestureRecognizer NS_AVAILABLE_IOS(3_2);
    
    // called when the recognizer attempts to transition out of UIGestureRecognizerStatePossible if a touch hit-tested to this view will be cancelled as a result of gesture recognition
    // returns YES by default. return NO to cause the gesture recognizer to transition to UIGestureRecognizerStateFailed
    // subclasses may override to prevent recognition of particular gestures. for example, UISlider prevents swipes parallel to the slider that start in the thumb
    - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer NS_AVAILABLE_IOS(6_0);

    UIView (UIViewMotionEffects)

    1.//添加移除运动影响
    /*! Begins applying `effect` to the receiver. The effect's emitted keyPath/value pairs will be
        applied to the view's presentation layer.
     
        Animates the transition to the motion effect's values using the present UIView animation
        context. */
    - (void)addMotionEffect:(UIMotionEffect *)effect NS_AVAILABLE_IOS(7_0);
    
    /*! Stops applying `effect` to the receiver. Any affected presentation values will animate to
        their post-removal values using the present UIView animation context. */
    - (void)removeMotionEffect:(UIMotionEffect *)effect NS_AVAILABLE_IOS(7_0);
    
    @property (copy, nonatomic) NSArray<__kindof UIMotionEffect *> *motionEffects NS_AVAILABLE_IOS(7_0);

    UIView (UISnapshotting)

    1.- (UIView *)snapshotViewAfterScreenUpdates:(BOOL)afterUpdates NS_AVAILABLE_IOS(7_0);

    截图,BOOL为NO

    - (UIView *)resizableSnapshotViewFromRect:(CGRect)rect afterScreenUpdates:(BOOL)afterUpdates withCapInsets:(UIEdgeInsets)capInsets NS_AVAILABLE_IOS(7_0); 

    指定区域截图

  • 相关阅读:
    JavaScript箭头函数 和 generator
    JavaScript闭包
    JavaScript高阶函数 map reduce filter sort
    JavaScript函数定义和调用 变量作用域
    python实现遗传算法求函数最大值(人工智能作业)
    PAT 1003
    制作U盘启动盘之后的恢复
    异步IO
    CCF201703-3 Markdown
    SQLAlchemy
  • 原文地址:https://www.cnblogs.com/hxwj/p/5217611.html
Copyright © 2020-2023  润新知