gpt4 book ai didi

ios - 单击 UIImageView SWIFT 不工作

转载 作者:行者123 更新时间:2023-11-29 01:00:27 25 4
gpt4 key购买 nike

有一个名为“imageView”的对象,我需要在单击“imageView”时始终调用函数“clicouCrosshair”,但它不起作用。我尝试了一些在互联网上找到的不同教程,但没有成功。有人知道为什么以及如何解决这个问题吗?

我认为问题是因为我将我的 View 用作 GMSMapView..在“prepareMap”函数中配置了“UIImageView”。

import UIKit
import GoogleMaps

class Maps_criarArea: UIViewController {

var projNome:String!;
var mapView:GMSMapView!;

var imageView:UIImageView!;

func clicouCrosshair(sender: AnyObject){
print("CROSSHAIR");
}

override func viewDidLoad() {
super.viewDidLoad();


GMSServices.provideAPIKey("AIzaSyB62KDZSGfbbN1IIVnlhewi4PpEZmxPJYM");


let centerBR_lat = -15.30;
let centerBR_lng = -49.57;

let cameraP = GMSCameraPosition.cameraWithLatitude(centerBR_lat, longitude: centerBR_lng, zoom: 4);
mapView = GMSMapView.mapWithFrame( CGRectZero, camera: cameraP)
mapView.myLocationEnabled = true
view = mapView;

self.prepareMap();
}

func prepareMap(){

let imageName = "crosshair";
let image = UIImage(named: imageName);
imageView = UIImageView(image: image!);

let screenSize: CGRect = UIScreen.mainScreen().bounds;
let WidthPosition = (screenSize.width*0.5)-32;
let heightPosition = (screenSize.height*0.5)-32;

imageView.frame = CGRect(x: WidthPosition, y: heightPosition, width: 64, height: 64);
imageView.userInteractionEnabled = true;


let detectTap = UITapGestureRecognizer(target: self, action: #selector(self.clicouCrosshair(_:)) )
//detectTap.numberOfTapsRequired = 1


imageView.addGestureRecognizer(detectTap)

mapView.addSubview(imageView);







}


override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}



//returning to view
override func viewWillAppear(animated: Bool) {
let saveBtn : UIBarButtonItem = UIBarButtonItem(title: "Salvar", style: UIBarButtonItemStyle.Plain, target: self, action: #selector(Maps_criarArea.salvar(_:)) )
self.navigationItem.rightBarButtonItem = saveBtn
}

func salvar(sender:UIBarButtonItem){

}

}

最佳答案

您的 UIImageView 在您的 GMSMapView 中,您的点击始终由 GMSMapView 处理。尝试忽略 GMSMapView 中的点击并将其传递给 UIImageView。添加UIGestureRecognizerDelegate在您查看并使用委托(delegate)方法 gestureRecognizerShouldBegin: 时。希望这会有所帮助。

关于ios - 单击 UIImageView SWIFT 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37058594/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com