我想刷我的圖像視圖,但沒有交換到左側。 我從frontcard陣列獲取圖像。我想在imageview中顯示並垂直滑動。滑動手勢不工作
我想這一個
FrontsCards =[[NSMutableArray alloc]initWithCapacity:9];
[FrontsCards insertObject:@"cloub1.png" atIndex:0];
[FrontsCards insertObject:@"cloub2.png" atIndex:1];
[FrontsCards insertObject:@"cloub3.png" atIndex:2];
[FrontsCards insertObject:@"cloub4.png" atIndex:3];
[FrontsCards insertObject:@"cloub5.png" atIndex:4];
[FrontsCards insertObject:@"cloub6.png" atIndex:5];
[FrontsCards insertObject:@"cloub7.png" atIndex:6];
[FrontsCards insertObject:@"cloub8.png" atIndex:7];
[FrontsCards insertObject:@"cloub9.png" atIndex:8];
- (void)viewDidLoad
{
[super viewDidLoad];
UISwipeGestureRecognizer *leftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftSwipeHandle:)];
leftRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
[leftRecognizer setNumberOfTouchesRequired:1];
[ImgView addGestureRecognizer:leftRecognizer];
}
- (void)leftSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer
{
int m = 0;
NSLog(@"Left Swipe");
AppDelegate * delegate=(AppDelegate *)[[UIApplication sharedApplication]delegate];
NSLog(@"%d",m);
for(m=0; m<[delegate.FrontsCards count];m++)
{
int randIdx=arc4random()%[delegate.FrontsCards count]; // Randomly shufffled
ImgView.userInteractionEnabled=YES;
ImgView.image=[UIImage imageNamed:[delegate.FrontsCards objectAtIndex:randIdx]];
NSLog(@"%d",m);
}
}
圖像不會被換到ImageView的。 如何解決我的問題幫我解決這個問題。 在此先感謝。
控制檯是否顯示來自leftSwipeHandle:方法的日誌? – Hacker
是否調用了'leftSwipeHandle'方法,是否檢查了中斷點 –
UIImageView將默認禁用userInteraction,您需要將其明確設置爲YES。 – Amar