【问题标题】:UIView Animation does not actually set new values?UIView 动画实际上并没有设置新值?
【发布时间】:2013-05-22 21:58:46
【问题描述】:

我遇到了 UI 动画问题。

我有一个 uiview:theView。

我为 theView 设置动画以移动到 mainView 上的某个随机位置。它从 A 点移动到 B 点,并将其比例从 1.0 更改为 1.5; 所以在动画之后,视图更大并且处于一个新的位置。

我通过按钮调用第二个动画。这一个只移动视图。 动画结束后,视图已经移动。但是,视图不再更大,它的比例又回到了 1.0。

那么这些动画值不会成为 theViews 的 size、position、ex 的新值吗?

我会尽快发布代码,因为这当然可能是我遗漏的一个粗心错误。

【问题讨论】:

  • 你是如何为你的视图设置动画的? CAAnimation 还是 UIView 动画?

标签: ios animation uiview resize position


【解决方案1】:

如果它的 UIView 动画。

- (void)viewDidLoad
{
    [super viewDidLoad];

        _yourView = [[UIView alloc]initWithFrame:CGRectMake(300, 300, 100, 100)];
        [_yourView setBackgroundColor:[UIColor redColor]];
        [self.view addSubview:_yourView];

        [UIView animateWithDuration:1.0f animations:^{
        [_yourView setFrame:CGRectMake(400, 400, 150, 150)];
        } completion:nil];

        UIButton *aMoveButton = [[UIButton alloc] initWithFrame:CGRectMake(10.0f, 5.0f, 60.0f, 40.0f)];
        [aMoveButton setTitle:@"MoveView" forState:UIControlStateNormal];
        [aMoveButton addTarget:self action:@selector(moveYourView) forControlEvents:UIControlEventTouchDown];
        [self.view addSubview:aMoveButton];

}

-(void)moveYourView{
    [UIView animateWithDuration:1.0f animations:^{
        [_yourView setFrame:CGRectMake(300, 500, 150, 150)];
    } completion:nil];
}

相信我这行得通,它实际上改变了视图的大小、位置值。

【讨论】:

  • 设置框架时您是对的。由于某种原因,TransformScale 的行为有所不同。
【解决方案2】:

我不能发表评论,所以我只想建议你说UIView,我不是 100% 确定,所以不要相信我的话,但我很确定你应该改用 UIImageView .希望能有所帮助:)

// create the view that will execute our animation
 UIImageView* campFireView = [[UIImageView alloc] initWithFrame:self.view.frame];

 // load all the frames of our animation
 campFireView.animationImages = [NSArray arrayWithObjects:    
                             [UIImage imageNamed:@"campFire01.gif"],
                             [UIImage imageNamed:@"campFire02.gif"],
                             [UIImage imageNamed:@"campFire03.gif"],
                             [UIImage imageNamed:@"campFire04.gif"],
                             [UIImage imageNamed:@"campFire05.gif"],
                             [UIImage imageNamed:@"campFire06.gif"],
                             [UIImage imageNamed:@"campFire07.gif"],
                             [UIImage imageNamed:@"campFire08.gif"],
                             [UIImage imageNamed:@"campFire09.gif"],
                             [UIImage imageNamed:@"campFire10.gif"],
                             [UIImage imageNamed:@"campFire11.gif"],
                             [UIImage imageNamed:@"campFire12.gif"],
                             [UIImage imageNamed:@"campFire13.gif"],
                             [UIImage imageNamed:@"campFire14.gif"],
                             [UIImage imageNamed:@"campFire15.gif"],
                             [UIImage imageNamed:@"campFire16.gif"],
                             [UIImage imageNamed:@"campFire17.gif"], nil];

 // all frames will execute in 1.75 seconds
 campFireView.animationDuration = 1.75;
 // repeat the annimation forever
 campFireView.animationRepeatCount = 0;
 // start animating
 [campFireView startAnimating];
 // add the animation view to the main window 
 [self.view addSubview:campFireView];

【讨论】:

  • @DTDev 是的,先生。您通过一系列图像播放动画。用一些示例代码查看我的原始答案:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-11-29
  • 1970-01-01
  • 2014-04-06
  • 2023-04-05
  • 1970-01-01
  • 2012-03-21
  • 1970-01-01
相关资源
最近更新 更多