
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() })}解决方法 创建视图后,需要将其userInteractionEnabled属性设置为true.然后你需要附加一个手势. 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可以兼容并使其执行某些 *** 作? (迅速)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)