2012-07-20 63 views
0

如何在用户触摸NSMutableArray中的图像后向上滑动webview 基本上我希望能够为每个图像提供触摸事件,如果用户触摸了图像“ban3.png”,它会向上滑动我已经创建的视图(WebView),我非常感谢您的帮助。如何在用户触摸NSMutableArray中的图像后向上滑动视图

代码

[imagesQueue = [[NSMutableArray alloc] init]; 
[imagesQueue addObject:[UIImage imageNamed:@"ban3.png"]]; 
[imagesQueue addObject:[UIImage imageNamed:@"ban1.png"]]; 
[imagesQueue addObject:[UIImage imageNamed:@"ban2.png"]]; 


//Put the last image on imageBack (UIImageView) 
imageBack.image = [imagesQueue objectAtIndex:[imagesQueue count] - 1]; 

//Insert the last image item from array to the first position 
[imagesQueue insertObject: imageBack.image atIndex:0]; 

//Remove the last image item from array 
[imagesQueue removeLastObject]; 

//Change UIImageView alpha 
//The desired opacity of the image, specified as a value between 0.0 and 1.0. 
//A value of 0.0 renders the image totally transparent while 1.0 renders it fully opaque. 
//Values larger than 1.0 are interpreted as 1.0. 
imageFront.alpha = 1.0; 
imageBack.alpha = 0.0; 

//Call nextImageAnimation add the next picture and produce the infinite loop 
[self nextImageAnimation];  

回答

0

通过你的阵列就循环,并添加UITapGestureRecognizer到每个图像:

for(UIView *image in self.myImages) 
{ 
    UITapGestureRecognizer* recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)]; 

    recognizer.numberOfTapsRequired = 1; 
    recognizer.numberOfTouchesRequired = 1; 
    [image addGestureRecognizer: recognizer]; 
} 

然后在您的handleTap:方法只是向上滑动您的视图(改变它的框架也许)。

相关问题