开发者

Can't Recognize Touch On navigation Bar's Image View.?

I have a View With Navigation Bar

Actually I have taken a Image View and Put it on a navigation bar....

As I want Button Not at right or Left but at somewhere on the navigation bar

By this method I can recognize touch on view but can not recognize touch on Navigation Bar ?

Can I change anything... In this method... Why?

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *) event {

    CGPoint p;
    p.x=0;
    p.y=0;

    p = [[touches anyObject] locationInView:self.nvbrCalculateBar];

    NSLog(@" %f",p.x);



    if(p.x==0 &开发者_如何学运维amp;& q.x==0)
    {

    }
    else
    { 

//Load View

    }

}


You can add a UITapGestureRecognizer to your UIImageView and that should do the trick

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapEvent:)];
[yourImageView addGestureRecognizer:tap];
[tap release];

- (void)tapEvent:(UITapGestureRecognizer *)gesture {
  //Do whatever you need when user taps the imageView
}

Also set the userInteractionEnabled of the imageView to YES to be able to receive the gesture recognizer events.

Hope this helps.


The UINavigationBar itself is not set to return touches, since I believe its not part of the actual UIView (for which the touchesBegan) method applies. Instead, you can push various items onto the nav bar (e.g. buttons) which you can define interactions for.

See its reference here.


USer Interaction Must be enabled of UINavigation Bar Property, And then Apply touch method..


Can you try:

    [imageView setUserInteractionEnabled:NO];

This should prevent your imageview to cancel the touches.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜