2013-03-30 157 views
0

我做我的應用程序這個滑動畫廊:IOS滾動畫廊

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(photoTap:)]; 
tap.numberOfTapsRequired = 1; 

int pageCount = 3; 
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 
                      0, 
                      360, 
                      200)]; 
scrollView.backgroundColor = [UIColor clearColor]; 
scrollView.pagingEnabled = YES; 
scrollView.contentSize = CGSizeMake(pageCount*scrollView.bounds.size.width , 
            scrollView.bounds.size.height); 

[scrollView addGestureRecognizer:tap]; 

CGRect viewsize = scrollView.bounds; 

UIImageView *image = [[UIImageView alloc]initWithFrame:viewsize]; 
[image setImage: [UIImage imageNamed:@"01.png"]]; 
image.userInteractionEnabled = YES; 
[scrollView addSubview:image]; 


viewsize = CGRectOffset(viewsize, scrollView.bounds.size.width, 0); 

UIImageView *image2 = [[UIImageView alloc]initWithFrame:viewsize]; 
[image2 setImage: [UIImage imageNamed:@"02.png"]]; 
image2.userInteractionEnabled = YES; 
[scrollView addSubview:image2]; 

- (void)photoTap:(UITapGestureRecognizer *) gestureRecognizer{ 
} 

我如何檢測其照片在我的滾動視圖挖? 我試圖添加手勢識別器的圖像,但只有最後一個工程。 有什麼建議嗎?謝謝

回答

0

您可以將手勢識別器添加到滾動視圖,在檢測到輕敲後,通過將點擊的座標添加到內容偏移來檢測其在UIScrollView內容上的位置。當你有這個座標時,我認爲檢測圖像不是問題。

+0

手勢識別器已被添加到滾動視圖。 – rmaddy