UIPopoverViewController 添加子视图很慢
我有一个 UIPopoverViewController 可以正确显示自定义 UIViewController 。当我单击按钮时,我会运行一个操作,因此我将一个视图添加到 UIViewController 视图的视图层次结构中。
问题是它非常慢,需要几秒钟才能显示视图。我没有对 UIViewController 的代码做任何不寻常的事情。
- (void)showAccountChooser {
self.twitterAccountPicker = [TwitterAccountPicker new];
[self.view addSubview:self.twitterAccountPicker.view];
self.twitterAccountPicker.view.frame = self.view.bounds;
self.twitterAccountPicker.view.transform = CGAffineTransformMakeScale(.05, .05);
[UIView animateWithDuration:0.5f animations:^{
self.twitterAccountPicker.view.transform = CGAffineTransformMakeScale(1, 1);
} completion:^(BOOL finished) {
//[self.twitterAccountPicker viewDidAppear:YES];
}];
}
我添加的 UIViewController 很简单,并且不会在 viewDidLoad 或 viewWill/DidAppear 中进行繁重的处理。我已经设置了断点并验证它没有做任何坏的事情。
还有其他人在添加视图时注意到这一点吗?
I have a UIPopoverViewController that is displaying a custom UIViewController properly. When I click a button I have an action run and as a result I add a view to the view hierarchy of the UIViewController's view.
The problem is that it is very slow, and takes several seconds for the view to appear. I'm not doing anything out of the ordinary with my UIViewController's code.
- (void)showAccountChooser {
self.twitterAccountPicker = [TwitterAccountPicker new];
[self.view addSubview:self.twitterAccountPicker.view];
self.twitterAccountPicker.view.frame = self.view.bounds;
self.twitterAccountPicker.view.transform = CGAffineTransformMakeScale(.05, .05);
[UIView animateWithDuration:0.5f animations:^{
self.twitterAccountPicker.view.transform = CGAffineTransformMakeScale(1, 1);
} completion:^(BOOL finished) {
//[self.twitterAccountPicker viewDidAppear:YES];
}];
}
The UIViewController that I'm adding is trivial and does not heavy processing in the viewDidLoad or viewWill/DidAppear. I have set break points and verified that it is not doing anything bad.
Anyone else notice this when adding views?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
设置断点尝试调试此问题后,我意识到我的 showAccountChooser 方法是从块调用中调用的,这是在后台线程上发生的。将此调用移至主线程解决了该问题。
After setting break points trying to debug this, I realized that my
showAccountChooser
method was being called from a block invoke, which was happening on a background thread. Moving this call to the main thread resolved the issue.