iOS动画会跳过元素

时间:2016-05-22 07:35:39

标签: ios swift animation uiimageview

我实现了一个欢迎屏幕,其中包含一组带有一组圆形图像的集合视图,这些图像是用户帐户。当用户点击其中一个单元格时,我创建一个新的UIImageView(不是真正创建,只是将一个隐藏的UIImageView移动到屏幕顶部),隐藏集合视图并向上移动键盘框架(最初位于下方)视图,y = view.frame.height)。 如果我没有将新创建的UIImageView的图像属性设置为原始单元格的图像,则一切正常。但是,如果我设置图像,键盘第一次不显示。所有其他动画都没有任何问题。只有键盘框架不会移动。然而,第二次尝试动画时,一切都按预期工作(图像属性不再改变,因为它是相同的图像)。如果我单击另一个单元格,则错误会重复,直到我第二次单击该单元格,此时它将按预期工作。

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
    selectedIndexPath = indexPath
    let cell = collectionView.cellForItemAtIndexPath(indexPath) as! UserCell
    userLoginImageView.hidden = false //UIImageView I keep around for the animation
    userLoginImageView.frame = cell.convertRect(cell.userImage.frame, toView: self.view) //Move it on top of the cell that was just clicked
    userLoginImageView.image = cell.userImage.image //This line causes the problem. If I comment it out, everything works perfectly.
    userLoginImageView.clipsToBounds = true
    resetPassword(false)

    UIView.animateWithDuration(0.3, delay: 0, options:
        UIViewAnimationOptions.CurveEaseOut, animations: {
            self.keyboardView.frame = CGRectMake(self.keyboardViewShownFrame!.minX, self.keyboardViewShownFrame!.minY, self.keyboardViewShownFrame!.width, self.keyboardViewShownFrame!.height) //Slide up the keyboard. This is the only animation that doesn't happen when I change the image
            self.userLoginImageView.frame = CGRectMake(self.view.frame.width/2 - 45, 40, 90, 90)
            self.collectionView.alpha = 0
            self.welcomeLabel.alpha = 0
            self.backButton.alpha = 1
            self.enterPinLabel.alpha = 1
            for view in self.passwordViews {
                view.alpha = 1
            }
    }, completion: nil)
}

欢迎屏幕:

首次点击后:

第二次点击(图片已加载):

0 个答案:

没有答案