我目前正在使用UISwipeGestureRecognisers和一系列图片的组合,但这并没有给我带来理想的效果。当我滑动图像时,刚出现但我的目标是水平滚动效果。
因此,例如,如果我部分滚动到左侧,我正在滚动的图像和我正在滚动的图像将在屏幕上。我确信这可以通过水平UIScrollView实现,但不知道如何做到这一点。
这就是我现在正在做的事情。
我的图片是从解析加载并存储在imagesArray中的:
query.findObjectsInBackgroundWithBlock { (objects: Array!, error: NSError!) -> Void in
if error != nil {
println("0 images found")
} else {
self.imagesArray.addObjectsFromArray(objects)
在我的viewDidload中设置手势识别器:
override func viewDidLoad() {
super.viewDidLoad()
var rightSwipe = UISwipeGestureRecognizer(target: self, action: "didSwipe:")
userImage.addGestureRecognizer(rightSwipe)
var leftSwipe = UISwipeGestureRecognizer(target: self, action: "didSwipe:")
leftSwipe.direction = UISwipeGestureRecognizerDirection.Left
userImage.addGestureRecognizer(leftSwipe)
}
我的didSwipe方法:
func didSwipe(sender: UISwipeGestureRecognizer) {
var direction = sender.direction as UISwipeGestureRecognizerDirection
switch (direction) {
case UISwipeGestureRecognizerDirection.Right:
println("swiped right")
case UISwipeGestureRecognizerDirection.Left:
println("swiped left")
println(imagesArray)
userImage.file = imagesArray.objectAtIndex(1)["image"] as PFFile
userImage.loadInBackground()
default:
println("ok")
}
}