首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >animateWithDuration:delay:options:animations:completion:不工作(奇怪)

animateWithDuration:delay:options:animations:completion:不工作(奇怪)
EN

Stack Overflow用户
提问于 2013-12-09 10:40:07
回答 2查看 794关注 0票数 0

我试图使用以下代码来翻译一个距离的UIView:

代码语言:javascript
复制
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)的位置。

由于我想在视图出现后将其动画化,所以我将代码放在viewDidAppear:中。但当我运行密码时,什么都没发生。

这里的self.exposureHintViewUIView的一个自定义子类,重要吗?

为什么?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-12-09 11:21:19

代码语言:javascript
复制
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[_AboutView setFrame:CGRectMake(0, 0, 320, 510)];
[UIView commitAnimations];

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

票数 1
EN

Stack Overflow用户

发布于 2013-12-09 11:29:39

我认为这里的问题是在没有编程代码的情况下在情节提要或XIB文件中创建exposureHintView。

试着做以下几点:

代码语言:javascript
复制
- (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时,无法在UIView中设置框架或转换或>>ViewDidLoad中的其他属性。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20468499

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档