来自阵列的UIImage幻灯片

时间:2016-04-27 20:53:50

标签: ios swift uiimageview uiimage

使用此Github扩展程序从URL设置图像:https://github.com/Haneke/HanekeSwift

我将图像存储在这样的数组中:

var userFile = [PFFile]()

图像存储为URL,我将图像设置在UIImageView内,如下所示:

imageView.hnk_setImageFromURL(NSURL(string: userFile[indexPath.row].url!)!, placeholder: nil, format: nil, failure: nil, success: nil)

如何在同一UIImageView中显示所有图片,但要查看下一张照片,我必须点按UIImageView

1 个答案:

答案 0 :(得分:0)

这是Obj-c示例如何做到这一点。在swift中,它非常相似。

为图像视图添加手势(点按)识别器:

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)];
[self.yourImageView addGestureRecognizer:tap];

然后点击:

- (void)tapped:(UIGestureRecognizer*)sender
{
    UIImageView* yourImageView = (UIImageView*)[sender view]; // touch is detected on the imageView

    yourImageView.image = // your image from url
}

夫特:

// setup gesture recognizer somewhere in the viewDidLoad:

let tap = UITapGestureRecognizer(target: self, action: #selector(handleTap))

 yourImageView.addGestureRecognizer(tap)

// this function will be called on tap
func handleTap(gestureRecognizer: UIGestureRecognizer)
{
    let tappedView = gestureRecognizer.view as! UIImageView
    tappedView.image = // add the image needed here
}