我想做滑动手势来UIView
连续滑动并从中获取数据。考虑每个UIView
. 我将数据存储在一个数组中并打印在UIView
while 转换的标签中。但是当我在显示所有数据程序停止工作后尝试滑动时。我的项目没有显示错误。请帮帮我。
这是我的数组:
addArray = [[NSMutableArray alloc]initWithCapacity:4];
[addArray insertObject:@"10" atIndex:0];
[addArray insertObject:@"20" atIndex:1];
[addArray insertObject:@"30" atIndex:2];
[addArray insertObject:@"40" atIndex:3];
flippedArray = [[NSMutableArray alloc] initWithCapacity:4];
[flippedArray insertObject:@"100" atIndex:0];
[flippedArray insertObject:@"200" atIndex:1];
[flippedArray insertObject:@"300" atIndex:2];
[flippedArray insertObject:@"400" atIndex:3];
这是我的手势识别器编码:
-(void)swipegesture:(UISwipeGestureRecognizer *)recognizer{
CGPoint location = [recognizer locationInView:additionalView];
if (recognizer.direction==UISwipeGestureRecognizerDirectionLeft)
{
if (increment<[addArray count])
{
NSLog(@"%d",[addArray count]);
increment++;
if(increment==[addArray count])
{
NSLog(@"Fail");
//[recognizer requireGestureRecognizerToFail:swipeGesture];
[recognizer setEnabled:NO];
}
else
{
additionalLabel.text=[[NSString alloc] initWithFormat:@"%@",
[addArray objectAtIndex:increment]];
flippedLabel.text = [[NSString alloc] initWithFormat:@"%@",
[flippedArray objectAtIndex:increment]];
NSLog(@"increment %d",increment);
[UIView animateWithDuration:0.55 animations:^{
[UIView setAnimationDelay:0.2];
}];
CATransition *animation = [CATransition animation];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionDefault]];
[animation setSpeed:0.4];
[[additionalView layer] addAnimation:animation forKey:nil];
}
}
}
else if(recognizer.direction==UISwipeGestureRecognizerDirectionRight)
{
if (increment>=0 && increment<[addArray count])
{
increment--;
if(increment>[addArray count])
{
additionalLabel.text=[[NSString alloc]initWithFormat:@"%@",
[addArray objectAtIndex:increment]];
flippedLabel.text=[[NSString alloc]initWithFormat:@"%@",
[flippedArray objectAtIndex:increment]];
NSLog(@"Decrement %d",increment);
[UIView animateWithDuration:0.55 animations:^{
[UIView setAnimationDelay:0.2];
}];
CATransition *animation = [CATransition animation];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromLeft];
[animation setTimingFunction:[CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionDefault]];
[animation setSpeed:0.4];
[[additionalView layer] addAnimation:animation forKey:nil];
}
}
}
}
仅增量时存在问题。我NSLog
打印失败。但是如果手势识别器达到[addArray count]
.