相关疑难解决方法(0)

在dispatch_async中正确引用self

如何在快速关闭中正确引用自我?

dispatch_async(dispatch_get_main_queue()) {
    self.popViewControllerAnimated(true)
}
Run Code Online (Sandbox Code Playgroud)

我收到错误:

Cannot convert the expression's type 'Void' to type 'UIViewController!"

随机我试过:

dispatch_async(dispatch_get_main_queue()) { ()
    self.popViewControllerAnimated(true)
}
Run Code Online (Sandbox Code Playgroud)

它起作用了.不确定extra()的作用!有人在乎解释吗?谢谢!

closures ios swift

9
推荐指数
1
解决办法
2062
查看次数

animateWithDuration:动画:完成:在Swift中

在objective-C中,我的动画位看起来像这样:

[UIView animateWithDuration:0.5 animations:^{
            [[[_storedCells lastObject] topLayerView] setFrame:CGRectMake(0, 0, swipeableCell.bounds.size.width, swipeableCell.bounds.size.height)];
        } completion:^(BOOL finished) {
            [_storedCells removeLastObject];
 }];
Run Code Online (Sandbox Code Playgroud)

如果我将其翻译成Swift,它应该看起来像这样:

 UIView.animateWithDuration(0.5, animations: {
                    self.storedCells[1].topLayerView.frame = CGRectMake(0, 0, cell.bounds.size.width, cell.bounds.size.height)
                }, completion: { (finished: Bool) in
                    //self.storedCells.removeAtIndex(1)
            })
Run Code Online (Sandbox Code Playgroud)

它在评论线上抱怨.我收到的错误是:Could not find an overload for 'animateWithDuration' that accepts the supplied arguments

我知道完成闭包需要一个布尔值并返回一个void,但是我应该能够写出一些与bool无关的东西....对吧?

任何帮助表示赞赏.

编辑:这是我如何在函数中声明我正在使用的数组:

var storedCells = SwipeableCell[]()
Run Code Online (Sandbox Code Playgroud)

一个采用SwipeableCell对象的数组.

closures animatewithduration swift ios8

8
推荐指数
1
解决办法
4889
查看次数

UIView.animateWithDuration完成

我有一个问题,关于在标题提到的方法中的迅速实施.如果我这样做:

leadingSpaceConstraint.constant = 0
UIView.animateWithDuration(0.3, animations: {
    self.view.layoutIfNeeded()
}, completion: { (complete: Bool) in
    self.navigationController.returnToRootViewController(true)
})
Run Code Online (Sandbox Code Playgroud)

我遇到以下问题:在调用中缺少参数'delay'的参数.只有在完成部分中有self.navigationController.returnToRootViewController()时才会发生这种情况.如果我将该语句提取为一个单独的方法,如下所示:

leadingSpaceConstraint.constant = 0
UIView.animateWithDuration(0.3, animations: {
    self.view.layoutIfNeeded()
}, completion: { (complete: Bool) in
    self.returnToRootViewController()
})

func returnToRootViewController() {
    navigationController.popToRootViewControllerAnimated(true)
}
Run Code Online (Sandbox Code Playgroud)

然后它完美地工作,完全符合我的要求.当然,这似乎不是理想的解决方案,更像是一种解决方案.任何人都可以告诉我我做错了什么或为什么Xcode(beta 6)这样做?

xcode uiviewanimation ios swift

3
推荐指数
1
解决办法
6081
查看次数