IOS学习之UIWindow和UIview的联系

IOS学习之UIWindow和UIview的联系

一、UIWindow:

1UIWindowLevel总共有三种级别:

UIWindowLevleNormal,

UIWindowLevelAlert;

UIWindowLevelStatusBar;

其中normal级别最低,再而是statusBar,级别最高的是alertView,alertView一般用来中断用户事件。打印出他们的值分别是0.0000,1000和2000

2、- (CGPoint)convertPoint:(CGPoint)point toWindow:(UIWindow *)window; // can be used to convert to another window

- (CGPoint)convertPoint:(CGPoint)point fromWindow:(UIWindow *)window; // pass in nil to mean screen

- (CGRect)convertRect:(CGRect)rect toWindow:(UIWindow *)window;

- (CGRect)convertRect:(CGRect)rect fromWindow:(UIWindow*)window

四个坐标转换

3、键盘的弹出、隐藏等通知是在UIWindow里面

4、要操作状态栏:由于状态栏stateBar是处于系统的Window上面,它的级别是UIWindowLevelStatusBar,所以我们可以自己创建一个Window级别为Alert的覆盖在上面


 

二、UIview:

1、动画曲线属性:四个

typedef NS_ENUM(NSInteger, UIViewAnimationCurve) {

UIViewAnimationCurveEaseInOut, // slow at beginning and end

UIViewAnimationCurveEaseIn, // slow at beginning

UIViewAnimationCurveEaseOut, // slow at end

UIViewAnimationCurveLinear

};

设置动画播放过程中是先快后慢还是线性等,设置动画曲线

2、动画过渡效果:左右上下翻转

typedef NS_ENUM(NSInteger, UIViewAnimationTransition) {

UIViewAnimationTransitionNone,

UIViewAnimationTransitionFlipFromLeft,

UIViewAnimationTransitionFlipFromRight,

UIViewAnimationTransitionCurlUp,

UIViewAnimationTransitionCurlDown,

};

 

3、设置内容模式:

typedef NS_ENUM(NSInteger, UIViewContentMode) {

UIViewContentModeScaleToFill,// 充满控件大小,会拉伸

UIViewContentModeScaleAspectFit,// 按照比例缩放,直到长或宽跟控件大小一样,会留空白

UIViewContentModeScaleAspectFill,//按照原比例缩放,直到最小边充满控件,会超出控件

UIViewContentModeRedraw,//重新绘画,会调用setNeedDisplay,跟第一个效果一样

UIViewContentModeCenter,// 居中,大小不变

UIViewContentModeTop,// 居顶部中间,大小不变

UIViewContentModeBottom,//底部中间,大小不变,下面类似

UIViewContentModeLeft,

UIViewContentModeRight,

UIViewContentModeTopLeft,

UIViewContentModeTopRight,

UIViewContentModeBottomLeft,

UIViewContentModeBottomRight,

};

 

4UIViewAutoresizingFlexibleLeftMargin自动调整左边与父控件的距离,也就是说距离父控件右边的距离不变,其他类似

 

5、动画属性:

typedef NS_OPTIONS(NSUInteger, UIViewAnimationOptions) {

UIViewAnimationOptionLayoutSubviews = 1 << 0,// 让子控件一起动画

UIViewAnimationOptionAllowUserInteraction = 1 << 1, // turn on user interaction while animating

UIViewAnimationOptionBeginFromCurrentState = 1 << 2, // start all views from current value, not initial value

UIViewAnimationOptionRepeat = 1 << 3, // repeat animation indefinitely重复

UIViewAnimationOptionAutoreverse = 1 << 4, // if repeat, run animation back and forth颠倒

UIViewAnimationOptionOverrideInheritedDuration = 1 << 5, // ignore nested duration

UIViewAnimationOptionOverrideInheritedCurve = 1 << 6, // ignore nested curve

UIViewAnimationOptionAllowAnimatedContent = 1 << 7, // animate contents (applies to transitions only)

UIViewAnimationOptionShowHideTransitionViews = 1 << 8, // flip to/from hidden state instead of adding/removing

UIViewAnimationOptionOverrideInheritedOptions = 1 << 9, // do not inherit any options or animation type

 

UIViewAnimationOptionCurveEaseInOut = 0 << 16, // default

UIViewAnimationOptionCurveEaseIn = 1 << 16,

UIViewAnimationOptionCurveEaseOut = 2 << 16,

UIViewAnimationOptionCurveLinear = 3 << 16,

 

UIViewAnimationOptionTransitionNone = 0 << 20, // default

UIViewAnimationOptionTransitionFlipFromLeft = 1 << 20,

UIViewAnimationOptionTransitionFlipFromRight = 2 << 20,

UIViewAnimationOptionTransitionCurlUp = 3 << 20,

UIViewAnimationOptionTransitionCurlDown = 4 << 20,

UIViewAnimationOptionTransitionCrossDissolve = 5 << 20,

UIViewAnimationOptionTransitionFlipFromTop = 6 << 20,

UIViewAnimationOptionTransitionFlipFromBottom = 7 << 20,

} NS_ENUM_AVAILABLE_IOS(4_0);

注意:在传参数的时候可以传多个,可以用|或来传多个参数

 

UIViewAnimationOptionAllowUserInteraction:打开用户交互,注意:这里打开用户交互只是允许用户点击,但是要注意的是比如你把一个图片或按钮从起始位置(0,0,100,100)动画转换到(200,200,100,100),在动画执行的时候,图片或按钮的位置已经变成(200,200,100,100)了,所以你必须在(200,200,100,100)范围里面点击才有效,在(0,0,100,100)里面点击是无效的。

 

6- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event

hitTest:用来决定哪个子视图响应事件。对于隐藏的控件或者是alpha值小于0.01的控件是无效的,不会调用这个函数,这个函数会递归调用-pointInside:withEvent:函数,要让某个控件不响应,可以重写这个函数并return NO,这样即使控件的userInteractionEnabled设置为YES也没有效果。

hitTest原理:它会将事件通过-pointInside:withEvent:一个个分发给子视图,如果返回YES,那么子视图的继承树就会被遍历,看哪一个子视图会响应,如果不响应,返回nil,会响应则返回self,递归结束

hitTest:withEvent: ===>调用pointInside:withEvent: ===> (point函数返回NO,结束分支,返回nil) //返回YES ===> (当前view没有subviewhitTest返回self) //当前viewsubviews ===>subviews的最上层view开始遍历,递归调用hitTest:withEvent:,直到hitTest返回第一个非nil对象 ===>(hitTest:withEvent:)

事件都是通过UIApplication来分发的,它有一个事件队列