开发者

UIImageview won't update after changing the center

开发者 https://www.devze.com 2023-01-20 22:32 出处:网络
I am trying to create a small augmented reality application where I move an image on top of开发者_如何学Go the camera capture. So the only thing I change is the center of the UIImageview:

I am trying to create a small augmented reality application where I move an image on top of开发者_如何学Go the camera capture. So the only thing I change is the center of the UIImageview:

[imageView1 setCenter:CGPointMake(x-16, 240)];  

and the center gets updated but the position of the image on the screen stays the same.

after the center update, this gets called:

[self.imageView1 performSelectorOnMainThread:@selector(setImage:) withObject:testImage waitUntilDone:YES];

The funny thing is that in the first iteration it actually updates the position. But only the first time. Any ideas?


Try:

imageView1.center = CGPointMake(imageView1.center.x-16, 240);


The accepted answer in this post (UIImageView not responding to centering) suggests that the problem is autolayout, which makes sense.

This post (Can I disable autolayout for a specific subview at runtime?) explains how to disable autolayout for specific elements.

Another answer suggest you add constraints (for x and y), create IBOutlets for these constrataints and update those to move the UI-element.

0

精彩评论

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

关注公众号