ios – 如何在Xcode中激活UIView的宽度和高度?
我有这个子视图,我想添加到我的主视图,但使它从原点扩展。我阅读了一些苹果文档,但我不明白我在做什么错误。我可以动画化框架的起点,即让它从任何地方滑入,但宽/高似乎不是动画。代码如下:
[UIView beginAnimations:@"animateAddContentView" context:nil]; [UIView setAnimationDuration:0.4]; customView.frame= CGRectMake(self.view.frame.origin.x +5,self.view.frame.origin.y +5,150); [self.view addSubview:customView]; customView.frame= CGRectMake(self.view.frame.origin.x +5,310,150); [UIView commitAnimations]; 我也尝试只将setFrame部分放在动画中,如下所示: customView.frame= CGRectMake(self.view.frame.origin.x +5,150); [self.view addSubview:customView]; [UIView beginAnimations:@"animateAddContentView" context:nil]; [UIView setAnimationDuration:0.4]; customView.frame= CGRectMake(self.view.frame.origin.x +5,150); [UIView commitAnimations]; 但它仍然不行! 编辑: 根据建议,我已将其移动到基于块的动画解决方案,这是确切的代码: NSLog(@"yourview : %@",customView); customView.frame= CGRectMake(self.view.frame.origin.x +5,150); NSLog(@"yourview : %@",customView); [self.view addSubview:customView]; NSLog(@"yourview : %@",customView); // [customView setFrame:CGRectMake( 0.0f,480.0f,customView.frame.size.width,customView.frame.size.height)]; [UIView animateWithDuration:0.4 delay:0 options:UIViewAnimationCurveEaseInOut animations:^ { NSLog(@"yourview : %@",customView); customView.frame = CGRectMake(self.view.frame.origin.x +5,150); NSLog(@"yourview : %@",customView); }completion:^(BOOL finished) { }]; 由于某种原因,这仍然不起作用。我看到的可能问题是: >我正在加载这个customView从一个笔尖,特别是310乘以150,也许这是一个问题。 在日志中的每个点,它提供正确的内容:例如,在目标帧之前,大小为0,150,并且在我将帧设置为310,150之后,但是动画不起作用! 解决方法
为了使视角“成长”到位,不要动画框架。动画转换。
从笔尖加载您的子视图。将其变换设置为0: view.transform = CGAffineTransformMakeScale(0,0); 然后将其添加到您的超级视图。 在动画块内,将变换设置为身份: view.transform = CGAffineTransformIdentity; 而视图将会增长到正常的大小。您可能需要调整锚点,使其从正确的点成长。 您还可以更改块内的框架,但是仅移动视图我更喜欢更改中心属性,如果还有变换,则不应该尝试设置框架。 对于奖励积分,您还可以将其动画化为略大于1.0的比例,然后在完成块中链接的动画中动画回到身份转换。这使得视图“弹出”出来,就像一个警报视图。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |