質問

I have added a custom view to my rootview and added a UITapGesture. When calling on the 'sender.view' of the UITapGesture code it no longer is represented by my custom UIView, but instead 'sender.view' is of type UIImageView.

So it really makes it hard to send messages to my custom view when iOS is expecting a UIView - the warning I get is: "Incompatible pointer types sending UIView to parameter CardView (my custom view).

I think it has to do with chain of response; the documentation says - "When iOS recognizes an event, it passes the event to the initial object that seems most relevant for handling that event, such as the view where a touch occurred." - About Events in iOS

The keyword here is "seems" - how can I tell iOS that my custom View is the one that should handle the gesture?

Question: How can I get sender.view to refer directly to my custom view?

Here is some code below:

//Creates the Card's view
CardView *cardView = [[CardView alloc]initWithFrame:CGRectMake(0, 0, 67,99)];
//For Single Tap
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleSingleTapGesture:)];
[cardView addGestureRecognizer:tapGesture];
[self.view addSubview:cardView];
役に立ちましたか?

解決

In the handleSingleTapGesture: will give u the (UITapGestureTecongnizer *)sender so cast like this:

CardView *card = (CardView *)sender.view;
//do you stuff with card 
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top