ios - Trouble getting UISwipeGestureRecognizer working, never detecting swipes? -


i trying setup simple swipe recognizer change text inside text label upon swiping. tried follow apple's tutorial here, swipe apparently never recognized, because text never changes. here did:

first, dragged swipe gesture recognizer object library view, , dropped on uiimageview.

next, control-click dragged swipe gesture recognizer bottom bar of view viewcontroller.h file seen here:

#import <uikit/uikit.h> @interface chordfirstviewcontroller : uiviewcontroller @property (strong, nonatomic) iboutlet uiswipegesturerecognizer *swiper; @property (weak, nonatomic) iboutlet uilabel *sampletext; @end 

then synthesized *swiper in .m file, , defined method follows:

#import "chordfirstviewcontroller.h" @interface chordfirstviewcontroller () @end  @implementation chordfirstviewcontroller @synthesize sampletext = _sampletext; @synthesize swiper = _swiper;  - (ibaction)swipermethod:(uiswipegesturerecognizer *)sender {     if (_swiper.direction == uiswipegesturerecognizerdirectionleft) {         _sampletext.text=@"hi";     } }  @end 

however, no matter swipes, can never change text. added button same _sampletext.text=@"hi" message, , worked fine, swiping no-go. can please me identify doing wrong here? thanks!

well. can set direction uiswipegesturerecognizer using direction property. if tried _swiper.direction == uiswipegesturerecognizerdirectionleft every time it'l false because here trying direction won't work.

for recognizing swipe direction can add different gestures different directions.the direction property defines allowed directions recognized swipes, not actual direction of particular swipe.

 uiswipegesturerecognizer *leftrecognizer = [[uiswipegesturerecognizer alloc] initwithtarget:self action:@selector(handleswipefromleft)]; [leftrecognizer setdirection: uiswipegesturerecognizerdirectionleft]; [[self view] addgesturerecognizer:leftrecognizer]; [leftrecognizer release];  uiswipegesturerecognizer *rightrecognizer = [[uiswipegesturerecognizer alloc] initwithtarget:self action:@selector(handleswipefromright)]; [rightrecognizer setdirection: uiswipegesturerecognizerdirectionright]; [[self view] addgesturerecognizer:rightrecognizer]; [rightrecognizer release]; 

edit:

-(void)handleswipefromright{ nslog(@"swipe right"); } 

and

-(void)handleswipefromleft{ nslog(@"swipe left"); } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -