Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 添加到UIImageView的按钮没有响应_Iphone_Objective C_Xcode_Uiimageview_Uibutton - Fatal编程技术网

Iphone 添加到UIImageView的按钮没有响应

Iphone 添加到UIImageView的按钮没有响应,iphone,objective-c,xcode,uiimageview,uibutton,Iphone,Objective C,Xcode,Uiimageview,Uibutton,我使用的是UIImageView,在我的应用程序中添加了两个按钮作为子视图。但是,如果我尝试单击按钮,它们将没有响应。这是有原因的,还是有解决办法 - (void)showPopover { if (isClicked == NO) { if (popover == nil) { popover = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Popover.png"]];

我使用的是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];
    }
}

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

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

将userInteractionEnabled设置为YES

对于UIImageView

此属性继承自 UIView父类。这个班 更改此属性的默认值 不动产


将userInteractionEnabled设置为YES

对于UIImageView

此属性继承自 UIView父类。这个班 更改此属性的默认值 不动产