UIScrollViewの上に置いたUILabelのタグをtouchesBeganで取得したいのですが、取得できません。
UIScrollViewの範囲外のself.viewのタグは取得できました。
どのように書けば良いでしょうか?
よろしくお願い致します。
swift
1 myScrollView = UIScrollView() 2 myScrollView.frame = CGRect(x: 10, y: 90, width: 300, height: self.view.frame.size.height) 3 let myImageView = UIImageView() 4 myImageView.frame = myScrollView.frame 5 myImageView.contentMode = UIViewContentMode.scaleAspectFill 6 myScrollView.addSubview(myImageView) 7 myScrollView.backgroundColor = UIColor.gray 8 myScrollView.isUserInteractionEnabled = true 9 myScrollView.alpha = 0.3 10 myScrollView.contentSize = CGSize(width:300, height:3800) 11 12 for var i in 1...Array.count-1{ 13 14 let shopImageView = UIImageView(frame: CGRect(x: 10, y: 10+(i*100)-90, width: 80, height: 80)) 15 shopImageView.image = UIImage(named: "gosei_1.jpg") 16 shopImageView.isUserInteractionEnabled = true 17 shopImageView.tag = i 18 myScrollView.addSubview(shopImageView) 19 20 nameLabel = UILabel(frame: CGRect(x: 120, y: 10+(i*100)-90, width: 170, height: 38)) 21 nameLabel.backgroundColor = UIColor.white 22 nameLabel.numberOfLines = 0 23 nameLabel.textColor = UIColor.black 24 nameLabel.isUserInteractionEnabled = true 25 nameLabel.tag = i 26 nameLabel.text = str2[Array[i]][0] 27 nameLabel.textAlignment = NSTextAlignment.left 28 nameLabel.adjustsFontSizeToFitWidth = true 29 myScrollView.addSubview(nameLabel) 30 31 addressLabel = UILabel(frame: CGRect(x: 120, y: 50+(i*100)-90, width: 170, height: 38)) 32 addressLabel.backgroundColor = UIColor.white 33 addressLabel.numberOfLines = 0 34 addressLabel.textColor = UIColor.black 35 addressLabel.isUserInteractionEnabled = true 36 addressLabel.tag = i 37 addressLabel.text = str2[Array[i]][1] 38 addressLabel.textAlignment = NSTextAlignment.left 39 addressLabel.adjustsFontSizeToFitWidth = true 40 myScrollView.addSubview(addressLabel) 41 42 } 43 44 45override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { 46 print("touchesBegan") 47 48 for touch: AnyObject in touches { 49 50 let t: UITouch = touch as! UITouch 51 52 print("\(t.view?.tag)") 53 54 if t.view?.tag == 1 { 55 NSLog("Label touched") 56 } 57 58 } 59 60} 61
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/10/31 01:39