简体   繁体   中英

What is the most efficient way of moving an UIImageView?

Currently I am doing it like this:

CGRect frameRect = myUIImageView.frame;
CGPoint rectPoint = frameRect.origin;
CGFloat newXPos = rectPoint.x + 10.5f;
landscape.frame = CGRectMake(newXPos, 0.0f, myUIImageView.frame.size.width, landscape.frame.size.height);

it feel that there is a more efficient solution. Maybe by using the center point?

Yes, you can move the center but the code is not significnaly more efficient. You could optimise out the CGPoint and assign the rect back directly:

CGRect frameRect = myUIImageView.frame; 
frameRect.origin.x += 10.5f;
landscape.frame = frameRect;

For that matter, you could just adjust the frame directly but, the optimiser will likely do this for you anyway.

What specifically are you not happy with? This doesn't seem like a good target to optimise. If your app's display is updating slowly, I suspect you are doing something else wrong.

我将“四处移动”放在一个动画块中,然后让iPhone进行移动。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM