2
我想做滑動手勢,連續滑動UIView
並從中獲取數據。考慮每個UIView
中的每個單詞。我將數據存儲在數組中,並在轉換時以UIView
的標籤打印。但是當我顯示所有數據程序停止工作後,試圖刷卡時。我的項目顯示沒有錯誤。請幫助我。滑動手勢滑動UIViews
這是我的數組:
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
打印爲FAIL。但是,如果它達到[addArray count]
的值,我不會如何停止手勢識別器。
正好。如果(增量<[addArray計數])檢查應該是如果(增量+ 1 <[addArray計數]) – Lefteris 2012-01-10 18:53:28
謝謝你這麼多的夥計...真的,我很高興看到你的答案... – 2012-01-11 05:59:37
它的工作完美.. 。 – 2012-01-11 06:00:03