Sunteți pe pagina 1din 4

static BOOL touchMoveFlag = FALSE; - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; touchMoveFlag = FALSE; gestureStartPoint

= [touch locationInView:self]; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint currentPosition = [touch locationInView:self]; if(touchMoveFlag) { CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x); CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y); if( deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance ) { if(currentPosition.x > gestureStartPoint.x) { [self previousButtonPressed]; } else { [self nextButtonPressed]; } } } } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ touchMoveFlag = TRUE; UITouch *touch = [touches anyObject]; CGPoint currentPosition = [touch locationInView:self]; if(touchMoveFlag) { CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x); CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y); if( deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance ) {

if(currentPosition.x > gestureStartPoint.x) { [self previousButtonPressed]; } else { [self nextButtonPressed]; } } } -(void)nextButtonPressed { imageId=imageId+1; if (imageId==[appDel.thumbImageList count]) { imageId=0; } appDel.thumbImageId=((PictureInfo*)[appDel.thumbImageList objectAtIndex:imageId]).pictureId; bookMarkId=[dataBaseConnect selectBookMarkId:appDel.thumbImageId]; if (bookMarkId==0) { [bookMarkButton setImage:[UIImage imageNamed:@"favoritesforgallery.png"] forState:UIControlStateNormal]; } else [bookMarkButton setImage:[UIImage imageNamed:@"favoritesforgallerytapped.png"] forState:UIControlStateNormal]; NSString *imageNAme=((PictureInfo*)[appDel.thumbImageList objectAtIndex:imageId]).pictureName; thisImageView.frame=CGRectMake(0, 0,self.frame.size.width, self.frame.size.height); [thisImageView setImage:[UIImage imageNamed:imageNAme]]; [self replaceSubview:thisImageView withSubview:thisImageView transition:kCATransitionPush direction:kCATransitionFromRight duration:0.5];

} -(void)previousButtonPressed {

imageId=imageId-1; if (imageId<0) { imageId=[appDel.thumbImageList count]-1; } appDel.thumbImageId=((PictureInfo*)[appDel.thumbImageList objectAtIndex:imageId]).pictureId; NSLog(@"previous imageid=%d",imageId); bookMarkId=[dataBaseConnect selectBookMarkId:appDel.thumbImageId]; if (bookMarkId==0) { [bookMarkButton setImage:[UIImage imageNamed:@"favoritesforgallery.png"] forState:UIControlStateNormal]; } else [bookMarkButton setImage:[UIImage imageNamed:@"favoritesforgallerytapped.png"] forState:UIControlStateNormal]; NSString *imageNAme=((PictureInfo*)[appDel.thumbImageList objectAtIndex:imageId]).pictureName; [thisImageView setImage:[UIImage imageNamed:imageNAme]]; [self replaceSubview:thisImageView withSubview:thisImageView transition:kCATransitionPush direction:kCATransitionFromLeft duration:0.5]; } -(void)replaceSubview:(UIView *)oldView withSubview:(UIView *)newView transition: (NSString *)transition direction:(NSString *)direction duration: (NSTimeInterval)duration { // Set up the animation CATransition *animation = [CATransition animation]; // Set the type and if appropriate direction of the transition, if (transition == kCATransitionFade) { [animation setType:kCATransitionFade]; } else { [animation setType:transition]; [animation setSubtype:direction]; } // Set the duration and timing function of the transtion -- duration is passed in as a parameter, use ease in/ease out as the timing function [animation setDuration:duration]; [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; [[oldView layer] addAnimation:animation forKey:kAnimationKey]; }

//define these variables on .h filehere imageId==strting index of array .. #define kMinimumGestureLength 100 #define kMaximumVariance 100 # define kAnimationKey @"transitionViewAnimation"

S-ar putea să vă placă și