开发者

UILabel not responding to touch [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot开发者_Python百科 be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.
    label_win3=[[UILabel alloc] initWithFrame:CGRectMake(55, 358, 210,15)];
            label_win3.text=@"Click here";
            label_win3.textColor=[UIColor cyanColor];
            label_win3.backgroundColor=[UIColor clearColor];
            label_win3.font=[UIFont fontWithName:@"Helvetica" size: 14.0];
            label_win3.textAlignment=UITextAlignmentCenter;

            label_win3.userInteractionEnabled=YES;


        [self.view addSubview:label_win3];



- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    CGPoint currentTouch = [touch locationInView:self.view];


    if([touch view]==label_win3) {

        [[NSNotificationCenter defaultCenter] postNotificationName:@"ShowRegistration" object:nil];}

     }


UILabels should and cannot respond to touch.

TextViews, TextFields, and Buttons all respond to touch.

Read the documentation if you are uncertain whether a particular UI element can have user interaction.


Having userInteractionEnabled means that touches are passed to the view. It does not mean that the view (UILabel) does something with them. UILabel is a very lightweight class. If you want to respond to touches on a UILabel, attach a UIGestureRecognizer to it, subclass it or use a custom UIButton. Many times, UIGestureRecognizer is the best solution for this (though you should use a UIButton whenever you can; it includes many specialized behaviors that are a pain to reproduce).

In any case, there is no reason for you to expect that your touchesBegan:withEvent: would be called. You were not touched. The UILabel was touched, and its touchesBegan:withEvent: was called. It then did nothing with that event as designed.

Jasarien is also correct that your question is very incomplete and confusing, but I think we've pieced it together.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜