简体   繁体   English

同时旋转和移动UIView并设置其中心点

[英]Rotate and move UIView simultaneously and set its center point

I'm making a game which uses multiple UIViews for its displaying of content. 我正在制作一个使用多个UIView进行内容显示的游戏。

There are 2 UIViews. 有2个UIView。 One of which is a map; 其中之一是地图; another is a plane. 另一个是飞机。 The plane's view is static. 飞机的视图是静态的。 It doesn't move, rotate, scale etc. I'd like to have the map translating under the plane, rotating at the same time. 它不会移动,旋转,缩放等。我想让地图在平面下平移,同时旋转。 The map's origin (or center point) needs to be set as the plane's center point every frame. 必须将地图的原点(或中心点)设置为每一帧的平面中心点。

How do I achieve this? 我该如何实现?

I'm using CGAffineTransform for this, and it works okay, until I want to turn round back on the map once I've left it. 我为此使用CGAffineTransform,它可以正常工作,直到离开后我想在地图上转回去。

Here's what I'm doing now: 这是我现在正在做的事情:

CGAffineTransform oldTransformation = CGAffineTransformTranslate(CGAffineTransformIdentity, 0, frames);
oldTransformation = CGAffineTransformRotate(oldTransformation, rotation);
cityView.transform = oldTransformation;

Any help appreciated. 任何帮助表示赞赏。

This blog here talks about using CAAnimationGroup to apply multiple animations (center point, rotation, and bounds) at the same time. 此博客在这里谈论使用CAAnimationGroup申请在同一时间多个动画(中心点,旋转和边界)。 It includes a sample application which you can get on github here . 它包括一个示例应用程序,您可以在github上找到它 (Note: run the app in iPad simulator). (注意:在iPad模拟器中运行该应用程序)。

The animation used in that project combines the simultaneous change of center point and rotation of a view. 该项目中使用的动画结合了中心点和视图旋转的同时更改。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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