IOS學習之UIWindow和UIview

來源:互聯網
上載者:User

一、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來分發的,它有一個事件隊列


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.