[英]Swift 360 image: How i can add a button in a panoramic image
我有一个图像,使用金属( https://github.com/ejeinc/MetalScope )将其转换为360度全景图像。 我如何在门上添加一个按钮(请参见屏幕截图),以便单击该按钮,它将转到具有不同全景图像的下一个控制器(另一个房间)
github项目: https : //github.com/Mahnach/MetalRender
您可以向图像添加轻击手势识别器,然后获得点击图像的位置。 如果在门附近轻按,则对下一个控制器执行锁定。 如果不确定门区域在哪里,则可以打印出触摸点并查看正在点击的图像上的位置。
override func viewDidLoad() {
super.viewDidLoad()
//Create Tap Gesture
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(tapAction(_:)))
//Enable image user interaction
self.imageView.isUserInteractionEnabled = true
//Add Tap gesture to the image
self.imageView.addGestureRecognizer(tapGestureRecognizer)
}
@objc func tapAction(_ sender: UITapGestureRecognizer){
//Get the touch point
let touchPoint = sender.location(in: self.imageView)
//Set the door area
let doorArea = CGRect(x: 200.0, y: 100.0, width: 75.0, height: 100.0)
//Then check if touch point is near door
if doorArea.contains(touchPoint){
//Peform segue
performSegue(withIdentifier: "nextScene", sender: nil)
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.