
- (NSLayoutConstraint*)newHIDdenConstraintAnimated:(BOol)animated { NSLayoutConstraint * constraint = [NSLayoutConstraint constraintWithItem:self.vIEw attribute:NSLayoutAttributeWIDth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplIEr:1 constant:NSWIDth(self.vIEw.frame)]; constraint.priority = NSLayoutPriorityrequired; CABasicAnimation * anim = [CABasicAnimation animation]; anim.timingFunction = [camediatimingFunction functionWithname:kcamediatimingFunctionEaSEOut]; anim.duration = 0.2; constraint.animations = [NSDictionary dictionaryWithObject:anim forKey:@"constant"]; [self.vIEw addConstraint:constraint]; [(animated ? constraint.animator : constraint) setConstant:0.0]; return constraint;} @H_403_7@这样做很美.不幸的是,稍后扩展窗格不太好. @H_403_7@ - (voID)removeHIDdenConstraintAnimated:(BOol)animated { if(!animated) { [self.vIEw removeConstraint:self.hIDdenConstraint]; } else { NSLayoutConstraint * constraint = self.hIDdenConstraint; NSVIEw * theVIEw = self.vIEw; [NSAnimationContext beginGrouPing]; [constraint.animator setConstant:self.wIDth]; [NSAnimationContext currentContext].completionHandler = ^{ [theVIEw removeConstraint:constraint]; }; [NSAnimationContext endGrouPing]; } self.hIDdenConstraint = nil;} @H_403_7@如果我插入一些时间码,我可以看到完成处理程序几乎立即触发,在有时间动画之前删除约束.在NSAnimationContext上设置持续时间没有任何影响. @H_403_7@任何想法,我可以在这里做错什么?解决方法 您必须首先设置完成处理程序,然后才将消息发送到动画师代理.否则,似乎在动画开始之后设置完成处理程序立即触发它,并且在动画有时间完成之前,常量被删除. 我刚刚检查了一个简单的代码: @H_403_7@ @H_403_7@
[NSAnimationContext beginGrouPing]; NSAnimationContext.currentContext.duration = animagionDuration; NSAnimationContext.currentContext.completionHandler = ^{[self removeConstraint:collapseConstraint];}; [collapseConstraint.animator setConstant:expandedHeight]; [NSAnimationContext endGrouPing]; @H_403_7@这样做完美,但如果在-setConstant之后设置完成处理程序,则动画无法运行. 总结 以上是内存溢出为你收集整理的可可 – NSLayoutConstraint.constant忽略动画全部内容,希望文章能够帮你解决可可 – NSLayoutConstraint.constant忽略动画所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)