UIImageView in UITableCell not clickable
I would suggest not changing the setting of userInteractionEnabled for the cell. You run the risk of messing up the functioning of the table view. Leave that alone.
How are you adding your image view to the cell? are you adding it to cell.contentView? (table views are UIViews, but the view that appears on the screen is the cell's content view)
Set the allowsSelection property on the table view to NO if you don't want the user to be able to select cells.
Added UIImageView to UITableViewCell outside cell's bounds
"This image is then displayed outside the bounds of the cell." your view will not receive touches outside it's bounds therefore the subview will not receive touches if it's parent does not
On click UIImageView SWIFT not working
As mentioned by mshresth the problem was with the recognization of the gestures like touch.
In order to solve this I change my approach to the problem, instead of trying to add a image with a GestureRecognizer inside a UIView that holds the map, i added the UIView inside the main UIView (view).
Add the map as sub view to view:
// PREPARA O MAPA
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
let screenSize: CGRect = UIScreen.mainScreen().bounds;
mapView.frame = CGRect(x: 0, y: 0, width: screenSize.width, height: screenSize.height);
view.addSubview(mapView);
and to add the image with the gestureRecognizer:
let imageName = "crosshair";
let image = UIImage(named: imageName);
let imageView:UIImageView = UIImageView(image: image!);
imageView.userInteractionEnabled = true;
imageView.frame = CGRect(x: (screenSize.width*0.5)-32, y: (screenSize.height*0.5)-32, width: 64, height: 64);
let detectTap = UITapGestureRecognizer(target: self, action: #selector(Maps_criarArea.clicouCrosshair(_:)) )
//detectTap.numberOfTapsRequired = 1
imageView.addGestureRecognizer(detectTap)
view.addSubview(imageView);
the fuction that contains both of the code above just have them inside it.
This way I was able to add the map, add the image and call a function when the image was pressed
Thanks to everybody who helped
Complete code:
import UIKit
import GoogleMaps
class Maps_criarArea: UIViewController {
var projNome:String!;
var mapView:GMSMapView!;
override func viewDidLoad() {
super.viewDidLoad();
GMSServices.provideAPIKey("AIzaSyB62KDZSGfbbN1IIVnlhewi4PpEZmxPJYM");
self.prepareMap();
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func prepareMap(){
// PREPARA O MAPA
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
let screenSize: CGRect = UIScreen.mainScreen().bounds;
mapView.frame = CGRect(x: 0, y: 0, width: screenSize.width, height: screenSize.height);
view.addSubview(mapView);
let imageName = "crosshair";
let image = UIImage(named: imageName);
let imageView:UIImageView = UIImageView(image: image!);
imageView.userInteractionEnabled = true;
imageView.frame = CGRect(x: (screenSize.width*0.5)-32, y: (screenSize.height*0.5)-32, width: 64, height: 64);
let detectTap = UITapGestureRecognizer(target: self, action: #selector(Maps_criarArea.clicouCrosshair(_:)) )
//detectTap.numberOfTapsRequired = 1
imageView.addGestureRecognizer(detectTap)
view.addSubview(imageView);
}
func clicouCrosshair(sender: AnyObject){
print("CROSSHAIR");
}
//returning to view
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(true)
let saveBtn : UIBarButtonItem = UIBarButtonItem(title: "Salvar", style: UIBarButtonItemStyle.Plain, target: self, action: #selector(Maps_criarArea.salvar(_:)) )
self.navigationItem.rightBarButtonItem = saveBtn
}
func salvar(sender:UIBarButtonItem){
print("salvar");
}
}
UIImage with UITapGestureRecognizer in first row of UITableViewController not working properly
Just in case someone runs into a similar issue as rare as that may be maybe this will help avoid someone going bald pulling their hair out. So my problem wasn't with the tableView itself but a sidebar I have that is similar to the facebook sidebar that slides in and out. My sidebar has a tableview in it and that table has a header on it that for some reason when it was right beside my other table was somehow preventing clicks to the image in that first row. My solution was simply to position that sidebar view a little bit further offscreen away from the view it was beside instead of being right next to it. Problem solved. Thanks to all who tried to help me out.
UILongPressGestureRecognizer bound only applicable on UIImageView
where you have added [self.customCam addGestureRecognizer:self.myImageView];
first add image view in custom view then add self.lpgr in myImageview.
replace this line [self.customCam addGestureRecognizer:self.lpgr];
by this
[myImageView addGestureRecognizer:self.lpgr]
; and try
UITableViewCell using QuickDialog : handle touch event on all the cell's surface
It seams you are assigning to the button the cell frame and then add it to the cell itself. In this way the position of the button is not the one you expect, and even though you can see the button it will not respond to touch because it resides outside the cell bounds.
Try to change this:
btn.frame = cell.frame;
to this:
btn.frame = cell.bounds;
Also when working with UItableViewCell remember to add subviews to its contentView and not the cell itself:
[cell.contentView addSubview:aCustomView];
Related Topics
Facebooksdk(4.1.X) Custom Login UI Button - Swift(1.2)
Check If My iOS Application Is Updated
How to Determine If a User Has an iOS App Installed
Dequeuereusablecellwithidentifier Never Returns Nil
Swiftui How to Align a View That's Larger Than Screen Width
How to Show "Would Like to Send You Push Notifications" Alert View Again
How to Create the Current Date (Or Any Date) as an Nsdate Without Hours, Minutes and Seconds
Cannot Invoke Initializer for Type 'Double' with an Argument List of Type '(String)'
403 Error: Disallowed_Useragent
Asynchronous Upload with Nsurlsession Will Not Work But Synchronous Nsurlconnection Does
Open App from Sms with My Url Scheme as a Link
How to Set the Rootviewcontroller with Swift, iOS 7
Removing Wkwebview Accesory Bar in Swift
Uitableviewcellaccessorycheckmark and Autolayout Constraints
Xcode Duplicate Symbols for Architecture Error After Updating Cocoa Pods
iOS 5 Gm: <Error>: More Than Maximum 5 Filtered Album Lists Trying to Register. This Will Fail
Objective-C Rabbitmq Client Not Publishing Messages to Queue