移动UIImageView的最有效方法是什么?

时间:2022-01-14 22:26:44

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?

它觉得有一个更有效的解决方案。也许通过使用中心点?

2 个解决方案

#1


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:

是的,你可以移动中心,但代码并没有显着提高效率。你可以优化CGPoint并直接分配回来:

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.

你特别不满意的是什么?这似乎不是优化的好目标。如果您的应用程序的显示缓慢更新,我怀疑您正在做其他错误。

#2


I put my 'moving around stuff' in an animation block, and let the iPhone do the moving.

我在动画块中放置了“移动的东西”,让iPhone动起来。

#1


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:

是的,你可以移动中心,但代码并没有显着提高效率。你可以优化CGPoint并直接分配回来:

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.

你特别不满意的是什么?这似乎不是优化的好目标。如果您的应用程序的显示缓慢更新,我怀疑您正在做其他错误。

#2


I put my 'moving around stuff' in an animation block, and let the iPhone do the moving.

我在动画块中放置了“移动的东西”,让iPhone动起来。