你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> IOS學習之UIWindow和UIview

IOS學習之UIWindow和UIview

編輯:IOS開發綜合

一、UIWindow:

1、UIWindowLevel總共有三種級別:

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,

};


4、UIViewAutoresizingFlexibleLeftMargin 自動調整左邊與父控件的距離,也就是說距離父控件右邊的距離不變,其他類似


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沒有subview,hitTest返回self) // 當前view有subviews ===>從subviews的最上層view開始遍歷,遞歸調用hitTest:withEvent:,直到hitTest返回第一個非nil對象 ===>(hitTest:withEvent:)

事件都是通過UIApplication來分發的,它有一個事件隊列


  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved