这是我的第一个问题,我是iOS编程的新手。旋转/移动一个uiview并同时移动其他人
我在网上搜索了很多来自于stackoverflow的技巧。我已经搜索了Xcode的帮助,并观看了视频等,但我似乎仍然无法得到这个工作。
我有一个约6个不同的UIViews视图。其中一个UIViews是位于垂直面板另一个UIView上方的箭头图像。箭头图像正在接收触摸,然后触发两种方法
一种方法将面板和箭头移动到右侧。另一种方法随着移动一起旋转箭头。
我已经试过CATransform3DMakeRotation
,CGAffineTransformMakeRotation
和CATransform3DMakeRotation
,但我不能让箭头与箭的移动和面板的移动旋转。
我已经能够实现的最好效果是CATransform3DMakeRotation
,但这只是翻转箭头,并且不会旋转动画。
其他人将旋转箭头,但不允许移动面板。
这里是我的代码来旋转箭头。正如你所看到的。很多评论了我尝试过的项目。
- (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];
}
}
谢谢马特。真棒回答。在我发布我原来的问题后不久。我发现了Core Animation,就像你说的那样使用它并且工作。我不明白为什么,直到你回答...谢谢。 – Matthew 2013-03-30 02:12:25
您可能想要阅读我的书的动画章节:http://www.apeth.com/iOSBook/ch17.html – matt 2013-03-30 02:15:28