gpt4 book ai didi

ios - 滑动手势不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:17:59 24 4
gpt4 key购买 nike

我想滑动我的 ImageView ,但没有切换到左侧。我从 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。如何解决我的问题帮我解决这个问题。提前致谢。

最佳答案

尝试使用这个。因为默认情况下图像的用户交互是NO。所以你需要设置用户交互YES

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];

// --------------- Add this line here ------------
ImgView.userInteractionEnabled = YES;
}

- (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.image=[UIImage imageNamed:[delegate.FrontsCards objectAtIndex:randIdx]];
NSLog(@"%d",m);
}
}

关于ios - 滑动手势不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16560865/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com