viewDidload 에
[self initGestureRecognizer]; initGestureRecognizer를 초기화 해준후
특정 제스쳐에 반응 에니메이션을 걸어준다.
- (void)initGestureRecognizer {
UISwipeGestureRecognizer *swipeRecognizer;
swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeHandler:)];
swipeRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeRecognizer];
[swipeRecognizer release];
swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeHandler:)];
swipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:swipeRecognizer];
[swipeRecognizer release];
UITapGestureRecognizer *tapRecognizer;
tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapHandler:)];
[tapRecognizer setNumberOfTapsRequired:1];
[self.view addGestureRecognizer:tapRecognizer];
[tapRecognizer release];
}
- (void)swipeHandler:(UISwipeGestureRecognizer *)recognizer {
NSString *obj;
if(recognizer.direction == UISwipeGestureRecognizerDirectionLeft) {
// directionLabel.text = @"Down";
imageIndex = (imageIndex > 0 )? imageIndex - 1: [imgName count]-1;
obj = kCATransitionFromRight;
}
else if(recognizer.direction == UISwipeGestureRecognizerDirectionRight) {
//directionLabel.text = @"Up";
imageIndex = (imageIndex < [imgName count]-1 )? imageIndex + 1 : 0 ;
obj = kCATransitionFromLeft;
}
CATransition *transition = [CATransition animation];
transition.duration = 0.5f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
transition.type = kCATransitionPush;
imageFrame.image = [UIImage imageNamed:[imgName objectAtIndex:imageIndex]];
transition.subtype = obj;
[imageFrame.layer addAnimation:transition forKey:nil];
'Developer > IOS' 카테고리의 다른 글
Timer use (0) | 2013.03.04 |
---|---|
메모리 릭 에러 memory leak (0) | 2013.02.28 |
마이피플과 카카오링크 로의 이미지 전달 (0) | 2013.02.26 |
UIDocumenet 에 저장 하기.. (0) | 2013.02.25 |
마이피플에 메시지 보내기.. (0) | 2013.02.25 |