2014-10-29 116 views
1

我想在MAGNIFY图标IOS设置约束的动画图标

执行下列约束动画在我希望我的图标是在我的屏幕的右边,然后将其移动到左边开始我文本框:

___________________ 
|___________________|   O- 

to 
    ___________________ 
O- |___________________|  

所以我所做的就是建立在优先级为1000 的图标,我的上海华权约束的,在优先级上的图标添加其他约束B,我的文本框的左侧750

然后当我想要perfo RM我的动画我删除约束A,所以我希望图标移动到我的texfield的左侧,但它没有移动

如何做到这一点?

约束答:

enter image description here

约束B:

[UIView animateWithDuration:0.5 animations:^{ 

    self.view.alpha = 1; 

} completion:^(BOOL finished) { 

    //animating the icon 
    [self.view removeConstraint:_loupeSuperviewLeftMargin];//remove constraint A 
    [self.view setNeedsUpdateConstraints]; 

    UIView animateWithDuration:0.5f animations:^{ 
     [self.view invalidateIntrinsicContentSize]; 
     [self.view layoutIfNeeded]; 
    }]; 
}]; 
+0

尝试在视图上调用invalidateIntrinsicContentSize以使其重新计算约束。 – Gismay 2014-10-29 15:51:53

+0

您是否需要将文本字段向右移动以为图标在其新位置腾出空间?你对文本字段有什么限制? – rdelmar 2014-10-29 16:17:46

+0

texfield位于我的超级视图中,我希望图标在其左侧滑动。调用invalidateIntrinsicContentSize什么也没做 – Mathieu 2014-10-29 16:19:41

回答

1

它的工作对我来说,如果我把图标:

enter image description here

动画的一些代码(我为我的te使用了一个按钮ST)这两个约束标签(低优先级的约束可以有任何优先级长达749 - 如果我使用750,这两种观点消失),

enter image description here

enter image description here

然后在代码中,我删除了高优先级的一个,

- (IBAction)moveButton:(id)sender { 
    [self.view removeConstraint:self.rightCon]; // rightCon is the high priority constraint 
    [UIView animateWithDuration:1 animations:^{ 
     [self.view layoutIfNeeded]; 
    }]; 

} 

确保您拨打removeConstraint上无论大家认为是有他们之间的间隔限制这两种观点的上海华 - 它是上海华说拥有这个约束。

+0

好吧我和你一样,除了在我的情况下,第一个约束的第一个项目是superview.trailing,而不是按钮 – Mathieu 2014-10-29 16:52:43

+1

@Mathieu,你的问题可能是这一行,[_searchIcon removeConstraint:_iconSuperviewLeftMargin]; 。这两个视图之间的约束属于superview,所以_searchIcon不拥有该约束,因此无法删除它。 – rdelmar 2014-10-29 16:55:20

+0

我编辑我的帖子来添加详细信息,它仍然不起作用 – Mathieu 2014-10-29 17:05:23