相关疑难解决方法(0)

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
查看次数

我在Swift中做错了什么来调用这个Objective-C块/ API调用?

我正在使用RedditKit将Reddit集成到一个应用程序中,而在Objective-C中,我调用API如下(并且它工作正常):

    [[RKClient sharedClient] signInWithUsername:@"username" password:@"password" completion:^(NSError *error) {
        RKPagination *pagination = [RKPagination paginationWithLimit:100];
        [[RKClient sharedClient] linksInSubredditWithName:subredditSelected pagination:pagination completion:^(NSArray *collection, RKPagination *pagination, NSError *error) {
             // code that executes on completion
        }];
    }];
Run Code Online (Sandbox Code Playgroud)

这是我在Swift中调用它的方式:

RKClient.sharedClient().signInWithUsername("username", password: "password", completion: { (error: NSError!) in
    RKClient.sharedClient().frontPageLinksWithPagination(RKPagination(limit: 50), completion: { (collection: RKLink[]!, pagination: RKPagination!, error: NSError!) in
        // code that executes on completion
    })
})
Run Code Online (Sandbox Code Playgroud)

但是我一直在使用Swift版本得到这个错误:

找不到接受提供的参数的'init'的重载

编辑:这是一个显示它的示例项目:http://cl.ly/3K0i2P1r3j1y

cocoa-touch objective-c swift ios8

4
推荐指数
1
解决办法
925
查看次数