大佬教程收集整理的这篇文章主要介绍了xcode – 如何使UIImageView可以兼容并使其执行某些操作? (迅速),大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
func createBlock(){ let imagename = "block.png" let image = UIImage(named: imageName) let imageView = UIImageView(image: image!) imageView.frame = CGRect(x: xPosition,y: -50,width: size,height: sizE) self.view.addSubview(imageView) UIView.animateWithDuration(duration,delay: delay,options: options,animations: { imageView.BACkgroundColor = UIColor.redColor() imageView.frame = CGRect(x: self.xPosition,y: 590,width: self.size,height: self.sizE) },completion: { animationFinished in imageView.removeFromSuperview() }) }
这是新代码:
func createBlock(){ let imagename = "block.png" let image = UIImage(named: imageName) let imageView = UIImageView(image: image!) imageView.frame = CGRect(x: xPosition,height: sizE) self.view.addSubview(imageView) imageView.userInteractionEnabled = true let tapRecognizer = UITapGestureRecognizer(target: self,action: SELEctor("imageTapped")) imageView.addGestureRecognizer(tapRecognizer) func imageTapped(gestureRecognizer: UITapGestureRecognizer) { let tappedImageView = gestureRecognizer.view! tappedImageView.removeFromSuperview() score += 10 } UIView.animateWithDuration(duration,animations: { imageView.BACkgroundColor = UIColor.redColor() imageView.frame = CGRect(x: self.xPosition,completion: { animationFinished in imageView.removeFromSuperview() }) }
imageView.userInteractionEnabled = true //Now you need a tap gesture recognizer //note that target and action point to what happens when the action is recognized. let tapRecognizer = UITapGestureRecognizer(target: self,action: SELEctor("imageTapped:")) //Add the recognizer to your view. imageView.addGestureRecognizer(tapRecognizer)
现在你仍然需要这个函数,在这种情况下是imageTapped:,这是识别手势时动作发生的地方.已识别的手势将作为参数发送,您可以从手势视图属性中找出从哪个图像视图中点击.
func imageTapped(gestureRecognizer: UITapGestureRecognizer) { //tappedImageView will be the image view that was tapped. //dismiss it,animate it off screen,whatever. let tappedImageView = gestureRecognizer.view! }
以上是大佬教程为你收集整理的xcode – 如何使UIImageView可以兼容并使其执行某些操作? (迅速)全部内容,希望文章能够帮你解决xcode – 如何使UIImageView可以兼容并使其执行某些操作? (迅速)所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。