I have an imageview predefined on the screen, I want to draw something on top of it, not exactly on it, but next to it, however, when I query [imageview frame.origin.x]
and [imageview frame.origin.y]
I always get 0, 0
, which is the top left corner of the screen, not the imageview. How do I get the x, y coordinates of the predefined imageview ?
This is my code for querying the image:
-(void) drawMyImage:(UIImage *)image nextTo:(UIImageView *)imageView{
CGRect frame = [imageView frame];
int startX = frame.origin.x+10;
int startY = frame.origin.y;
UIImageView *myImageView = [[UIImageView alloc]initWithFrame:CGRectMake(startX,startY,frame.size.width,frame.size.height)];
myImageView .image = image;
[myImageView setNeedsDisplay];
}
And my image is always drawn in the top left corner of the screen. How can I fix this?
答案是我在 viewDidLoad 中定义了所有内容,当我应该在 viewDidAppear 中完成时,当 IB 对象有框架时
我认为您应该使用浮点值而不是使用 int。
Try to change [myImageView setNeedsDisplay];
to [imageView addSubView:myImageView];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.