Ios 旋转/移动一个uiview并同时移动其他uiview
这是我在这里的第一个问题,我是iOS编程的新手 我在网上到处搜索,从stackoverflow那里得到了很多提示。我搜索了Xcode帮助并观看了视频等,但我似乎仍然无法实现这一点 我有一个视图,大约有6个不同的视图。其中一个UIView是垂直面板的另一个UIView上方的箭头图像。箭头图像接收到触摸,然后触发两种方法 一种方法是将面板和箭头向右移动。另一种方法是随着移动旋转箭头 我已经尝试了Ios 旋转/移动一个uiview并同时移动其他uiview,ios,objective-c,uiview,rotation,move,Ios,Objective C,Uiview,Rotation,Move,这是我在这里的第一个问题,我是iOS编程的新手 我在网上到处搜索,从stackoverflow那里得到了很多提示。我搜索了Xcode帮助并观看了视频等,但我似乎仍然无法实现这一点 我有一个视图,大约有6个不同的视图。其中一个UIView是垂直面板的另一个UIView上方的箭头图像。箭头图像接收到触摸,然后触发两种方法 一种方法是将面板和箭头向右移动。另一种方法是随着移动旋转箭头 我已经尝试了CATTransferM3DMakeRotation、CGAffineTransformMakeRotat
CATTransferM3DMakeRotation
、CGAffineTransformMakeRotation
和CATTransferM3DMakeRotation
,但我无法使箭头随着箭头的移动和面板的移动而旋转
我所能达到的最好效果是使用CATTransferorM3dMakeRotation
,但这只是翻转箭头,而不会设置旋转动画
其他人将旋转箭头,但不允许移动面板
这是我旋转箭头的代码。
如你所见。我试过的很多东西都被注释掉了
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInView:self.view];
CGRect bugRect = [[[RightArrow layer] presentationLayer] frame];
if (CGRectContainsPoint(bugRect, touchLocation)) {
[self RotateArrowOFF];
[self MovePanels];
NSLog(@"Arrow tapped!");
} else {
NSLog(@"Arrow not tapped.");
return;
}
}
-(IBAction)MoveLeftColorPanel
{
NSLog(@"Right Arrow Center %@", NSStringFromCGPoint(RightArrow.center));
}
- (void)MovePanels
{
if (_PanelsAreOffScreen == NO) {
[UIView animateWithDuration:0.3f delay:0 options:UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionLayoutSubviews animations:^{
RightPanel.center = CGPointMake(1065, 384);
}
completion:^(BOOL finished) {
NSLog(@"Animation 1 complete");
_PanelsAreMoving = YES;
}];
[UIView animateWithDuration:0.3f delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
LeftPanel.center = CGPointMake(-50, 384);
}
completion:^(BOOL finished) {
NSLog(@"Animation 2 complete");
_PanelsAreMoving = YES;
}];
[UIView animateWithDuration:0.3f delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
RightArrow.center = CGPointMake(1010, 82);
}
completion:^(BOOL finished) {
NSLog(@"Animation 3 complete");
_PanelsAreMoving = YES;
}];
_PanelsAreOffScreen = YES;
}
else {
[UIView animateWithDuration:0.3f delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
RightPanel.center = CGPointMake(914, 384);
}
completion:^(BOOL finished) {
NSLog(@"Animation 5 complete");
}];
[UIView animateWithDuration:0.3f delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
LeftPanel.center = CGPointMake(108, 384);
}
completion:^(BOOL finished) {
NSLog(@"Animation 6 complete");
}];
[UIView animateWithDuration:0.3f delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
RightArrow.center = CGPointMake(836, 82);
}
completion:^(BOOL finished) {
NSLog(@"Animation 7 complete");
}];
_PanelsAreOffScreen = NO;
}
}
- (void)RotateArrowOFF//:(CGRect)rect
{
RightArrow.layer.anchorPoint = CGPointMake(0.06, 0.5);
if (_PanelsAreOffScreen == NO)
{
[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
[CATransaction setValue:[NSNumber numberWithFloat:2.0f] forKey:kCATransactionAnimationDuration];
CATransform3D RotateArrow = RightArrow.layer.transform;
RotateArrow = CATransform3DMakeRotation(M_PI,0.0,0.0,1.0);
RightArrow.layer.transform = RotateArrow;
}
else
{
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat:2.0f] forKey:kCATransactionAnimationDuration];
CATransform3D RotateArrow = RightArrow.layer.transform;
RotateArrow = CATransform3DMakeRotation(0,0.0f,0.0f,1.0f);
RightArrow.layer.transform = RotateArrow;
[CATransaction commit];
}
}
所以你的问题是,为什么这里没有动画?问题是RightArrow是一个UIView,因此RightArrow.layer
是它的“底层”。不能仅通过指定视图的属性来隐式设置视图底层的动画。必须使用UIView动画(使用视图的transform
属性),否则必须直接使用核心动画(CABasicAnimation)
下面是一个例子(来自我的书):
谢谢你,马特。真棒的回答。在我发布我的原始问题后不久。我找到了核心动画,使用了它,它工作了,就像你说的。我真的不明白为什么,直到你回答。。。谢谢。你可能想看看我的书中关于动画的章节:
RightArrow.layer.transform = RotateArrow;
[CATransaction setDisableActions:YES];
v.layer.transform = CATransform3DRotate(v.layer.transform, M_PI/4.0, 0, 0, 1);
CABasicAnimation* anim = [CABasicAnimation animationWithKeyPath:@"transform"];
anim.duration = 0.8;
[v.layer addAnimation:anim forKey:nil];