0
我想显示一个旋转对象的图像动画。 我有一个NSArray
与对象的帧,我想逐帧显示它们的属性为UIImageView
animationImages
。逐帧动画与UIGestureRecognizer
问题是我想用UISwipeGestureRecognizer
(右和左)来控制动画。取决于手势的速度,对象应该旋转得更快或更慢。我认为这是不可能的,因为它被称为一次而不是连续的手势。
(注:这是我在StackOverflow上的第一个问题)
预先感谢您
编辑:我只是张贴我的解决方案。也许它对任何人都有用。我认为这很有用。
首先:向视图添加手势。
self.recognizer = [[UISwipeGestureRecognizer alloc] init];
self.recognizer.cancelsTouchesInView=NO;
[self.view addGestureRecognizer:self.recognizer];
其次:在tocuhMoved方法我显示我取决于先前触摸的方向的需要的帧。它由用户的事件调用。
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
NSInteger image= [self.animationView.animationImages indexOfObject:self.animationView.image];
UITouch *touch = [touches anyObject];
NSLog(@"Touch moved with index:%i", image);
if ((positionTouch.x<[touch locationInView:self.animationView].x)) {
if (image==24) {
self.animationView.image=[self.animationView.animationImages objectAtIndex:0];
}
else{
self.animationView.image=[self.animationView.animationImages objectAtIndex:image+1];
}
}
else if((positionTouch.x>[touch locationInView:self.animationView].x)){
if (image==0) {
self.animationView.image=[self.animationView.animationImages objectAtIndex:24];
}
else{
self.animationView.image=[self.animationView.animationImages objectAtIndex:image-1];
}
}
positionTouch= [touch locationInView:self.animationView];
}
不要忘记<UIGestureRecognizerDelegate>
用这种方法,我补帧的阵列...
-(void)addPictures{
NSMutableArray* mArray=[[NSMutableArray alloc]initWithCapacity:25];
for (int i=0; i<25; i++) {
[mArray insertObject:[UIImage imageNamed:[NSString stringWithFormat:@"Picture %i.jpg", i+1]] atIndex:i];
}
self.animationView.image=[mArray objectAtIndex:0];
self.animationView.animationImages=mArray;
[self.view addSubview:self.animationView];
}
谢谢。我会尝试这个选项。 – TomCobo