没有滞后的动画?

时间:2013-04-28 22:34:33

标签: iphone animation uiview sdk addsubview

我目前正在使用以下代码为视图之间的转换设置动画,并且在执行此操作时调用refreshTheServers方法时,整个应用程序冻结,刷新服务器,然后显示视图。

如何使视图成为一个无缝的过程,然后刷新服务器?

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:NO];
[self.view addSubview:self.folderView];
[UIView commitAnimations];
[self refreshTheServers];

编辑:这是我的refreshTheServers方法的代码:

- (void)refreshTheServers {

KeychainItemWrapper* keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"KeychainTest" accessGroup:nil];

NSString *userForConnect = [NSString stringWithFormat:@"%@", [keychain objectForKey:(__bridge id)(kSecAttrAccount)]];
NSString *passForConnect = [NSString stringWithFormat:@"%@", [keychain objectForKey:(__bridge id)(kSecValueData)]];



CTCoreAccount *account = [[CTCoreAccount alloc] init];

dispatch_queue_t taskQ = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

dispatch_async(taskQ, ^{
    [account connectToServer:[[NSUserDefaults standardUserDefaults]
                              stringForKey:@"server"]
                        port:993
              connectionType:CTConnectionTypeTLS
                    authType:CTImapAuthTypePlain
                       login:userForConnect
                    password:passForConnect];

    dispatch_async(dispatch_get_main_queue(), ^{
        // ... the thread is over, do stuff on the main thread ...

        CTCoreFolder *inbox = [account folderWithPath:theAppDelegate.folder];

        NSArray *inboxMessages = [inbox messagesFromUID:1 to:0 withFetchAttributes:CTFetchAttrEnvelope];

        [[self allMessages] removeAllObjects];
        [[self allMessages] addObjectsFromArray:inboxMessages];

        [self.messagesTable reloadData];
    });
});
}

我做错了什么?

1 个答案:

答案 0 :(得分:0)

以下调用是同步的: [inbox messagesFromUID:1到:0 withFetchAttributes:CTFetchAttrEnvelope]; 这就是应用程序冻结的原因。 仪器CPU采样器可以突出显示。