我试图在屏幕上获取触摸的坐标,以显示弹出菜单
如何在页面视图控制器中使用
我在这里做错了什么?
function getAvengers() {
return $http.get('https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA')
.then(getAvengersComplete)
.catch(getAvengersFailed);
function getAvengersComplete(response) {
return response.data;
}
function getAvengersFailed(error) {
console.log('XHR Failed for getAvengers.' + error.data);
}
}
TestCtrl.dataTest = dataservice.getAvengers();
console.log(TestCtrl.dataTest.status);
答案 0 :(得分:12)
在PageViewController中,如果你想弹出
在viewDidLoad中:
let tap = UITapGestureRecognizer(target: self, action: "showMoreActions:")
tap.numberOfTapsRequired = 1
view.addGestureRecognizer(tap)
让页面视图控制器继承UIGestureRecognizerDelegate
,然后添加:
func showMoreActions(touch: UITapGestureRecognizer) {
let touchPoint = touch.locationInView(self.view)
let DynamicView = UIView(frame: CGRectMake(touchPoint.x, touchPoint.y, 100, 100))
DynamicView.backgroundColor=UIColor.greenColor()
DynamicView.layer.cornerRadius=25
DynamicView.layer.borderWidth=2
self.view.addSubview(DynamicView)
}
答案 1 :(得分:2)
快捷键5:
override func viewDidLoad() {
super.viewDidLoad()
let tap = UITapGestureRecognizer(target: self, action: #selector(touchedScreen(touch:)))
view.addGestureRecognizer(tap)
}
@objc func touchedScreen(touch: UITapGestureRecognizer) {
let touchPoint = touch.location(in: self.view)
print(touchPoint)
}