2

画像ビューをスワイプしたかったのですが、左側にスワップしませんでした。フロントカード配列から画像を取得します。そして、イメージビューで表示して縦にスワイプしたかったのです。

私はこれを試しました

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 にスワップされません。私の問題を解決する方法はこれを助けてくれます。前もって感謝します。

4

5 に答える 5

3

これを使ってみてください。デフォルトでは、画像のユーザー インタラクションは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);
    }
}
于 2013-05-15T09:09:51.147 に答える
2

.h ファイル内

int imgCount;

.m ファイルで

- (void)viewDidLoad  {
    [super viewDidLoad];

    ImgView.userInteractionEnabled=YES;
    UISwipeGestureRecognizer *leftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftSwipeHandle:)];
    leftRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
    [leftRecognizer setNumberOfTouchesRequired:1];
    [ImgView addGestureRecognizer:leftRecognizer];

    imgCount = 0;
}

- (void)leftSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer {
    AppDelegate * delegate=(AppDelegate *)[[UIApplication sharedApplication]delegate];
    ImgView.image=[UIImage imageNamed:[delegate.FrontsCards objectAtIndex:imgCount]];
    imgCount++;
    if (imgCount >= 9) {
       imgCount = 0;
    }
}
于 2013-05-15T09:18:21.630 に答える
1

これを試して

[ImgView addGestureRecognizer:leftRecognizer];
//Add this
ImgView.userInteractionEnabled = YES;
于 2013-05-15T09:10:38.297 に答える
0

imageview.userInteractionEnabled = YES;に設定する必要がありますUIImageView

于 2013-05-15T09:08:20.643 に答える
0

これを試して。

UISwipeGestureRecognizer *leftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftSwipeHandle:)];
leftRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
[leftRecognizer setNumberOfTouchesRequired:1];
[ImgView addGestureRecognizer:leftRecognizer];
ImgView.userInteractionEnabled = YES;

UIImageViewデフォルトでは無効になっています。有効にする必要があります。

于 2013-05-15T09:27:54.730 に答える