Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.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
Objective c 无法在目标c中的imageview上正确设置按钮框_Objective C_Uibutton_Imageview_Frame - Fatal编程技术网

Objective c 无法在目标c中的imageview上正确设置按钮框

Objective c 无法在目标c中的imageview上正确设置按钮框,objective-c,uibutton,imageview,frame,Objective C,Uibutton,Imageview,Frame,我正在图像视图上设置一个按钮,但无法获得正确的帧。我不明白为什么。以下是问题的图像: 我试着用轻拍手势;那没用。我尝试通过引用imageview的边界和框架来设置框架,但这也不起作用 可能是,您应该阅读更多有关UIView的frame和bound属性之间差异的信息。 在代码中,您应该使用: clearButton.frame = [self.imageView convertRect:self.imageView.bounds toView:self.view]; [self.view add

我正在图像视图上设置一个按钮,但无法获得正确的帧。我不明白为什么。以下是问题的图像:

我试着用轻拍手势;那没用。我尝试通过引用imageview的边界和框架来设置框架,但这也不起作用


可能是,您应该阅读更多有关UIView的
frame
bound
属性之间差异的信息。 在代码中,您应该使用:

clearButton.frame = [self.imageView convertRect:self.imageView.bounds toView:self.view];
[self.view addSubview:clearButton];


设置clearButton的框架并将其添加到父视图中。

感谢您略带屈尊和半正确的回答。第二个解决方案不起作用,因为按钮作为imageview的子视图放置时不会触发。您的第一个解决方案生成的结果类似于我刚刚更新的google文档顶部的图像。@djax imageView是self的子视图吗?我已经更新了案例的第一个解决方案(如果不是)。我还更新了第二个解决方案。我更新了第一个解决方案,使用UIViewclearButton.frame=[self.imageView convertRect:self.imageView.bounds-toView:self.view]的convertRect:toView:method;似乎也不起作用。在clearButton.frame=[self.imageView-convertRect:self.imageView.bounds-toView:self]行中;我得到了“自我”的警告,因为这不应该是自我观点吗?
clearButton.frame = self.imageView.bounds;
[self.imageView addSubview:clearButton];
self.imageView.userInteractionEnabled = YES;