Ios 动画宽度持续时间:延迟:选项:动画:完成:不工作(奇怪)

Ios 动画宽度持续时间:延迟:选项:动画:完成:不工作(奇怪),ios,objective-c,uiview,core-animation,Ios,Objective C,Uiview,Core Animation,我正在尝试使用以下代码将UIView转换一段距离: CGAffineTransform transform = CGAffineTransformMakeTranslation(-100, -100); [self.exposureHintView setTransform:transform]; [UIView animateWithDuration:2.0 delay:0.0 options:UIViewAn

我正在尝试使用以下代码将UIView转换一段距离:

CGAffineTransform transform = CGAffineTransformMakeTranslation(-100, -100);
[self.exposureHintView setTransform:transform];
[UIView animateWithDuration:2.0
                      delay:0.0
                    options:UIViewAnimationOptionBeginFromCurrentState
                 animations:^{
                     NSLog(@"Begin!");
                     CGAffineTransform newTrans = CGAffineTransformMakeTranslation(0, 0);
                     [self.exposureHintView setTransform:newTrans];
                 }
                 completion:^(BOOL finished) {
                     NSLog(@"End %d", finished);
                 }];
因此,基本上,我正在尝试将视图从某个点移动,比如说
(-100,-100)
,移动到相对于自身的
(0,0)

因为我想在视图出现后对其进行动画处理,所以我将代码放在
viewdide:
中。但是当我运行代码时,什么也没发生

self.exposureHintView
这里是
UIView
的一个自定义子类,这有关系吗

为什么?


使用此代码更改视图的位置

我认为这里的问题是,您在序列图像板或XIB文件中创建exposureHintView时没有编程代码

请尝试执行以下操作:

- (void)viewDidLoad
{
    //Init exposureHintView
    UIView* exposureHintView = [[UIView alloc]initWithFrame(sampleFrame)];
    [self addSubView: exposureHintView];

    //Set transform
    CGAffineTransform transform = CGAffineTransformMakeTranslation(-100, -100);
    [self.exposureHintView setTransform:transform];

    //Commit animation
    [UIView animateWithDuration:2.0 delay:0.0
                     options:UIViewAnimationOptionBeginFromCurrentState
                     animations:^{
          NSLog(@"Begin!");
          CGAffineTransform newTrans = CGAffineTransformMakeTranslation(0, 0);
          [self.exposureHintView setTransform:newTrans];
    }
    completion:^(BOOL finished) {
        NSLog(@"End %d", finished);
    }];

这里的原因是,当您使用故事板或XIB时,您无法在>>ViewDidLoad中设置此UIView的帧或变换或某些其他属性。我发现这在模拟器上有问题-我建议在真实设备上测试。我正在使用真实设备。。。如何解决这个问题?发布你的代码公开HintViewThanks,但我不知道为什么转换不起作用?
- (void)viewDidLoad
{
    //Init exposureHintView
    UIView* exposureHintView = [[UIView alloc]initWithFrame(sampleFrame)];
    [self addSubView: exposureHintView];

    //Set transform
    CGAffineTransform transform = CGAffineTransformMakeTranslation(-100, -100);
    [self.exposureHintView setTransform:transform];

    //Commit animation
    [UIView animateWithDuration:2.0 delay:0.0
                     options:UIViewAnimationOptionBeginFromCurrentState
                     animations:^{
          NSLog(@"Begin!");
          CGAffineTransform newTrans = CGAffineTransformMakeTranslation(0, 0);
          [self.exposureHintView setTransform:newTrans];
    }
    completion:^(BOOL finished) {
        NSLog(@"End %d", finished);
    }];