【问题标题】:Buttons added to a UIImageView are unresponsive添加到 UIImageView 的按钮无响应
【发布时间】:2011-04-24 12:02:05
【问题描述】:

我正在使用 UIImageView,在我的应用中添加了两个按钮作为子视图。但是,如果我尝试单击按钮,它们将无响应。这是有原因的,还是解决办法?

- (void)showPopover {
    if (isClicked == NO) {
        if (popover == nil) {
            popover = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Popover.png"]];
            [popover setFrame:CGRectMake(190, -10, 132, 75)];
            UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
            [btn1 setFrame:CGRectMake(30, 30, 24, 24)];
            [btn1 setBackgroundColor:[UIColor clearColor]];
            [btn1 setImage:[UIImage imageNamed:@"Bookmark.png"] forState:UIControlStateNormal];
            [btn1 addTarget:self action:@selector(addFav) forControlEvents:UIControlStateNormal];
            [popover addSubview:btn1];

            UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
            [btn2 setFrame:CGRectMake(80, 30, 24, 24)];
            [btn2 setBackgroundColor:[UIColor clearColor]];
            [btn2 setImage:[UIImage imageNamed:@"ButtonBarReload.png"] forState:UIControlStateNormal];
            [btn2 addTarget:self action:@selector(doHud) forControlEvents:UIControlStateNormal];
            [popover addSubview:btn2];
            isClicked = YES;
        }
        popover.alpha = 0.0;
        isClicked = YES;
        [self.view.superview addSubview:popover];
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:1.0];
        popover.alpha = 1.0;
        [UIView commitAnimations];
    }
    else if (isClicked == YES) {
        [popover setAlpha:1.0];
         isClicked = NO;
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:1.0];
        [popover setAlpha:0.0];
        [popover removeFromSuperview];
        [UIView commitAnimations];
        popover = nil;
        [popover release];
    }
}

【问题讨论】:

    标签: iphone objective-c xcode uiimageview uibutton


    【解决方案1】:

    默认情况下,图像视图设置为禁用用户交互。试试imageView.userInteractionEnabled = YES;

    【讨论】:

      【解决方案2】:

      将 userInteractionEnabled 设置为 YES

      对于 UIImageView....

      此属性继承自 UIView 父类。这节课 更改此的默认值 属性为NO。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-07
        • 1970-01-01
        • 2015-03-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多