0

images を含む水平スクロール テーブルビューを作成しています。スワイプ機能がうまく機能しており、画像を次のように追加できscrollViewますcellForRowAtIndexPath

scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, tv.frame.size.width, 78)];
    [scrollView setContentSize:CGSizeMake(700, 78)];
    UIImage *footImage = [UIImage imageNamed:@"Foot.png"];
    UIImageView *footImageView = [[UIImageView alloc] initWithImage:footImage];
    footImageView.frame = CGRectMake(0, 0, 80, 78);
    footImageView.userInteractionEnabled = YES;
    [scrollView addSubview: footImageView];

    UIImage *handImage = [UIImage imageNamed:@"Hand.png"];
    UIImageView *handImageView = [[UIImageView alloc] initWithImage:handImage];
    handImageView.frame = CGRectMake(90, 0, 80, 78);
    handImageView.userInteractionEnabled = YES;
    [scrollView addSubview: handImageView];

    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(highlightImage)];
    [scrollView addGestureRecognizer:tapGesture];
    NSLog(@"tapGesture added to scrollView");


    [[cell contentView] addSubview:scrollView];

    pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 50, tv.frame.size.width, 50)];
    [pageControl setNumberOfPages:4];
    [[cell contentView] addSubview:pageControl];

tapGestureはセレクターに登録しており、hightlightImageこのメソッドを正しく呼び出していることをログに記録しています。

- (void) highlightImage
{
    NSLog(@"tapping tapping");
}

私が本当に取り組んでいるのは、タップするとこれらの画像を強調表示/選択し、もう一度タップするとそれらを強調表示/選択解除する機能です。次のページに移動する別のボタンを画面に表示します (ここでは関係ありません)。

ここで正しい道を進んでいますか?明らかに、私はNSArrayofUIImagesを入力し、scrollViewそのように入力しますが、今のところそれをスパイクするだけです. 誰かが私に指示や、各ボタンを個別に選択可能/選択解除可能にする方法の例を教えてくれたら、それは素晴らしいことです:)

4

1 に答える 1

2

UIImageView の代わりに UIButton を使用します。

機能が組み込まれていselectedます。

ジェスチャーを取り除き、すべてのボタンにアクションとして highlightImage を追加します。

あなたhighlightImageを作るhighlightImage:(id)sender

送信者はボタンでなければならないので、あなたはただ行うことができます

[送信者 setSelected:YES];

于 2011-02-27T01:54:54.067 に答える