在我的Xib中。我已经包含了3个子视图和3个小图像视图
![我必须将动画包含在右侧滑动中并分别左键滑动每个视图。对于一个视图的简单滑动可以根据滑动项目获得收藏的方向正常工作,图像位置也可以更改] [2]
//........towards right Gesture recogniser for swiping.....//
UISwipeGestureRecognizer *rightRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightSwipeHandle:)];
rightRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
[rightRecognizer setNumberOfTouchesRequired:1];
[self.view addGestureRecognizer:rightRecognizer];
//........towards left Gesture recogniser for swiping.....//
UISwipeGestureRecognizer *leftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftSwipeHandle:)];
leftRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
[leftRecognizer setNumberOfTouchesRequired:1];
[self.view addGestureRecognizer:leftRecognizer];
- (void)rightSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer
{
NSLog(@"Right Gesture");
self.Favimage.hidden = false;
self.closeImage.hidden = true;
}
- (void)leftSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer
{
NSLog(@"Left Gesture");
self.Favimage.hidden = true;
self.closeImage.hidden = false;
}
这是我现在尝试的。我必须用更好的动画做到这一点。提前致谢
答案 0 :(得分:1)
- (void)rightSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer
{
NSLog(@"Right Gesture");
self.closeImage.hidden = true;
// self.shoe.hidden = true;
//Do moving
CGRect finalFrame = CGRectMake(150,5, 64, 63);
[UIView animateWithDuration:0.5 animations:^{
_shoe.frame = finalFrame;
self.Favimage.hidden = true;
} completion:^(BOOL finished) {
self.Favimage.hidden = false;
// [_Favimage removeFromSuperview];
//[_Favimage removeFromSuperview];
//[self.view removeGestureRecognizer:gestureRecognizer];
}];
}
- (void)leftSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer
{
NSLog(@"Left Gesture");
self.Favimage.hidden = true;
self.closeImage.hidden = false;
CGRect finalFrame = CGRectMake(77,5, 70, 63);
[UIView animateWithDuration:0.5 animations:^{
_shoe.frame = finalFrame;
} completion:^(BOOL finished) {
//self.Favimage.hidden = false;
//[_Favimage removeFromSuperview];
//[_Favimage removeFromSuperview];
//[self.view removeGestureRecognizer:gestureRecognizer];
}];
// do moving
}
尝试这个