我创建了简单UIScrollView
的图像。每次按下图像时,我都想更改该图像,我该怎么做?
我创建它并用图像UIScrollView
初始化它。NSMutableArray
UIScrollView *myScroll = [[UIScrollView alloc] initWithFrame: CGRectMake (0,100,200,30)];
NSMutableArray = *images = [NSMutableArray alloc] initWithObjects: img1,img2,img3,nil];
for (int i=0; i<3; i++)
{
UIImageView *imageV = [UIImageView alloc];
[imageV setImage:[images objectAtIndex:i]];
[myScroll addSubview:imageV];
[imageV release];
}
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget: self action:@selector (changeImg:)];
[myScroll addGestureRecognizer: singleTap];
以及我在卷轴上被触摸的地方的感触:
- (void) singleTapGestureCaptured:(UITapGesturerecongnizer *) gesture
{
CGPoint touch = [gesture locationInView:myScroll];
}
通过触摸项目的 X,Y 我知道选择了什么图像
在这里,我需要更改例如 myScroll 的第一张图片...我该怎么做?