<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                用戶對屏幕(人機交互)的所有操作都可稱為事件。事件包括用戶點擊,觸摸和手勢識別等。 一:UIView及UIViewController都繼承自UIResponder類,而具有在屏幕上顯示功能的類及其控制器類(UIControl)也都繼承自UIView,所以他們都時響應者(即所有視圖和所由控件都是響應者)。 ### 內容結構圖: ![](https://box.kancloud.cn/2016-06-12_575cce81e44cd.png) 二:響應著鏈:事件是向上傳遞的(這點類似于java中的異常處理:throw),當當前響應者處理不了事件的時,他會將此事件傳遞給他的父視圖,逐級向更高一層(下一個對象)傳遞。 如果窗口處理不了當前事件,此事件將會被傳遞到應用程序的UIApplication實例。如果還是處理不了,此事件將進入睡眠狀態。 響應者鏈圖: ![](https://box.kancloud.cn/2016-06-12_575cce8245840.png) 轉發事件:從上面可以看到,事件是在逐個對象間的傳遞,當視圖(如:表視圖)不包含動作事件(如:輕掃手勢)時,可能不會執行傳遞工作,這樣其他對象將無法獲得響應,阻止了其他視圖的手勢識別。這時就需要手動去傳遞:在下一個響應者上調用相同的方法來傳遞該對象, ~~~ -(void)responder:(UIEvent*)event{ //如果可處理傳遞事件,執行此句: [self handleEvent:event ]; //否則手動傳遞到下一個響應者(遞歸) [self.nextResponder responder:event ]; } ~~~ 三: ?4個通知手勢的方法: 1.開始觸摸: ~~~ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesMoved:touches withEvent:event]; //touches :動作的數量() ?每個對象都是一個UITouch對象,而每一個事件都可以理解為一個手指觸摸。 //獲取任意一個觸摸對象 UITouch *touch = [touches anyObject]; //獲得觸摸對象的點擊數量,只捕捉一個觸摸對象的點擊。 NSInteger numTaps=[touch tapCount]; //獲得觸摸對象的數量 NSInteger numTouchs=[touches count]; //觸摸對象的位置 CGPoint previousPoint = [touch previousLocationInView:self.view]; ~~~ 2.移動: ~~~ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { } ~~~ 3.離開: ~~~ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { } ~~~ 4.取消: ?電話呼入等中斷手勢時,會調用此方法。 ~~~ - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { } ~~~ 四:手勢識別器(UIGestureRecognizer):可以理解成一個容器,里面可添加它的子類(如:捏合(UIPinchGestureRecognizer),輕掃(UISwiperGestureRecognizer),點擊(UITapGestureRecognizer)),這些子類都是封裝好的,可響應屏幕上的事件進行處理。當然也可自定義手勢識別器的子類,來響應需要的事件,這樣顯得更靈活些。 1.調用系統的手勢識別器 以捏合為例: ~~~ - (void)viewDidLoad { [super viewDidLoad]; //實例化捏合手勢識別器,將實例好的手勢識別器對象作為實參傳遞到doPinch:。 UIPinchGestureRecognizer *pinch = [[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(doPinch:)] autorelease]; //將實例化捏合手勢識別器加入視圖識別器中。 [self.view addGestureRecognizer:pinch]; } - (void)doPinch:(UIPinchGestureRecognizer *)pinch { //如果開始觸發 if (pinch.state == UIGestureRecognizerStateBegan) { CGFloat initialFontSize = label.font.pointSize; } else { //按照捏合比例擴大或縮小 label.font = [label.font fontWithSize:initialFontSize * pinch.scale]; } } ~~~ ### 2.自定義手勢識別器: 自定義MyGestureRecognizerView。 MyGestureRecognizerView.h ~~~ #import <UIKit/UIKit.h> @interface MyGestureRecognizerView : UIGestureRecognizer @end ~~~ MyGestureRecognizerView.m ~~~ #import "MyGestureRecognizerView.h" @implementation MyGestureRecognizerView - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesBegan:touches withEvent:event]; //可以填寫自己所需要的識別機制。。。。。。 //獲取任意一個觸摸對象 UITouch *touch = [touches anyObject]; //獲得觸摸對象的點擊數量,只捕捉一個觸摸對象的點擊。 NSInteger numTaps=[touch tapCount]; //獲得觸摸對象的數量 NSInteger numTouchs=[touches count]; //觸摸對象的位置 CGPoint previousPoint = [touch previousLocationInView:self.view]; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesMoved:touches withEvent:event]; //可以填寫自己所需要的識別機制。。。。。。。 } @end ~~~ ### 在主視圖控制器中: HelloViewController.h ~~~ #import <UIKit/UIKit.h> @interface HelloViewController : UIViewController @end ~~~ HelloViewController.m ~~~ #import "HelloViewController.h" #import "MyGestureRecognizerView.h" @interface HelloViewController () @end @implementation HelloViewController - (void)viewDidLoad { MyGestureRecognizerView *mygest=[[MyGestureRecognizerView alloc] initWithTarget:self action:@selector(doit:)]; [self.view addGestureRecognizer:mygest]; [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } -(void)doit:(MyGestureRecognizerView *)my{ } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); } @end ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看