我是UIView,我繼承UIResponder,
所以我除了擁有觸碰與動感的能力外,我還負責畫面的繪製與動畫。
所以我除了擁有觸碰與動感的能力外,我還負責畫面的繪製與動畫。
我是UIControl,我繼承UIView,除了擁有觸碰、動感、與畫面繪製與動畫的能力外,我還針對使用者提供使用者基本互動能力。
UIResponder
iOS的觸碰功能由我而生,我處理了使用觸碰相關的事件,當然我也針對iOS搖動的動作感應進行事件處理,因此我有以下能力:
回覆觸碰事件
- – touchesBegan:withEvent:
- – touchesMoved:withEvent:
- – touchesEnded:withEvent:
- – touchesCancelled:withEvent:
回覆動感事件
除此之後還作一些基本的回覆能力:
管理輸入視圖
- inputView property
- inputAccessoryView property
- – reloadInputViews
管理回應鏈"Responder Chain"
回覆遠端控制事件
取得復原管理器"undoManager"
- undoManager property
驗證可執行的動 作
UIView
為了要讓iOS的螢幕上有視覺化的視圖,因此我UIView提供繪圖與動畫的能力,讓iOS螢幕上長出一個一個畫面外還可以加上動畫的效果,因此我有以下能力:
初使化視圖物件
設定事件行為
- userInteractionEnabled property
- multipleTouchEnabled property
- exclusiveTouch property
視定視圖的顯示效果
- backgroundColor property
- hidden property
- alpha property
- opaque property
- clipsToBounds property
- clearsContextBeforeDrawing property
- + layerClass
- layer property
設定邊界與框架
管理視圖的階層
- superview property
- subviews property
- window property
- – addSubview:
- – bringSubviewToFront:
- – sendSubviewToBack:
- – removeFromSuperview
- – insertSubview:atIndex:
- – insertSubview:aboveSubview:
- – insertSubview:belowSubview:
- – exchangeSubviewAtIndex:withSubviewAtIndex:
- – isDescendantOfView:
繪製與更新視圖
管理手勢
- – addGestureRecognizer:
- – removeGestureRecognizer:
- gestureRecognizers property
- – gestureRecognizerShouldBegin:
為視圖加上動畫
- + animateWithDuration:delay:options:animations:completion:
- + animateWithDuration:animations:completion:
- + animateWithDuration:animations:
- + transitionWithView:duration:options:animations:completion:
- + transitionFromView:toView:duration:options:completion:
點擊測試
UIView的其他能力請參考:http://developer.apple.com/library/ios/#documentation/uikit/reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/cl/UIView
繼承UIView的視圖有:
- UILabel
- UIActionSheet
- UIProgressView
- UIPickerView
- UIImageView
- UIWebView
- UIActivityIndicatorView
- UITextView
- UIToolbar
- UIAlertView
UIControl
為了讓使用者更輕鬆使用iOS,我UIControl定義了一些使用者常用來操作iOS的,好在使用者發生對應的操作事件時進行處理。
設定控制項的屬性
- state property
- enabled property
- selected property
- highlighted property
- contentVerticalAlignment property
- contentHorizontalAlignment property
追蹤觸碰與重繪控制項
- – beginTrackingWithTouch:withEvent:
- – continueTrackingWithTouch:withEvent:
- – endTrackingWithTouch:withEvent:
- – cancelTrackingWithEvent:
- tracking property
- touchInside property
準備和傳作操作訊息
- – sendAction:to:forEvent:
- – sendActionsForControlEvents:
- – addTarget:action:forControlEvents:
- – removeTarget:action:forControlEvents:
- – actionsForTarget:forControlEvent:
- – allTargets
- – allControlEvents
enum { UIControlEventTouchDown = 1 << 0, UIControlEventTouchDownRepeat = 1 << 1, UIControlEventTouchDragInside = 1 << 2, UIControlEventTouchDragOutside = 1 << 3, UIControlEventTouchDragEnter = 1 << 4, UIControlEventTouchDragExit = 1 << 5, UIControlEventTouchUpInside = 1 << 6, UIControlEventTouchUpOutside = 1 << 7, UIControlEventTouchCancel = 1 << 8, UIControlEventValueChanged = 1 << 12, UIControlEventEditingDidBegin = 1 << 16, UIControlEventEditingChanged = 1 << 17, UIControlEventEditingDidEnd = 1 << 18, UIControlEventEditingDidEndOnExit = 1 << 19, UIControlEventAllTouchEvents = 0x00000FFF, UIControlEventAllEditingEvents = 0x000F0000, UIControlEventApplicationReserved = 0x0F000000, UIControlEventSystemReserved = 0xF0000000, UIControlEventAllEvents = 0xFFFFFFFF };
當然,只要是繼承自UIControl的控制項,都可在Interface Builder按右鍵,以IBAction的方式連結事件,下圖中"Sent Events",就是我UIControl定義給使用者操作的事件。
繼承UIControl的控制項有:
- UIButton
- UISwitch
- UISilder
- UIStepper
- UITextField
- UIPageControl
- UIDatePicker
- UISegmentedControl