Dar*_*ren 6 ios uicollectionview
我在iOS 7.1中使用UIDocumentInteractionController,它的表现非常糟糕.
我在UICollectionViewController中使用它来查看集合视图中的文档.
按下集合视图中的项目时,大约需要6秒(是的,那是6)秒.从用户体验的角度来看,他们在出现之前已经多次按下屏幕,因为它需要很长时间.
我从iOS 6开始使用相同的代码,但现在看起来特别糟糕.如果有人对如何加快速度有任何想法,那将非常感激.
基本上,我的头文件中有以下内容:
interface MyViewController : UICollectionViewController <UIDocumentInteractionControllerDelegate>
{
UIDocumentInteractionController *docController;
}
@end
Run Code Online (Sandbox Code Playgroud)
在实施中,我只是做以下事情:
在viewDidLoad中(最近移到这里看它是否改进了东西):
docController = [[UIDocumentInteractionController alloc] init];
docController.delegate = self;
Run Code Online (Sandbox Code Playgroud)
然后在collectionView:didSelectItemAtIndexPath中:我这样做:
NSURL *fileURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:document.Link ofType:@"" ]];
[docController setURL:fileURL];
PresentationViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"DocumentCell" forIndexPath:indexPath];
CGRect rect1 = cell.frame;
bool didShow = [docController presentOptionsMenuFromRect:rect1 inView:collectionView animated:YES];
Run Code Online (Sandbox Code Playgroud)
其中document只是一个带有URL字符串的类.
如果您需要任何进一步的细节,请告诉我.
提前感谢任何人都可以提供的帮助.
- 更新:在一些NSLog之后,我注意到它肯定是下面的那条缓慢的行:
bool didShow = [docController presentOptionsMenuFromRect:rect1 inView:collectionView animated:YES];
Run Code Online (Sandbox Code Playgroud)
长话短说:
您使用的方法是同步请求,它使用您的文档数据来查找哪些应用程序能够读取您的文件。您需要与异步版本进行交换,该版本将枚举限制为仅可以解析您的文件类型的应用程序。
删除这个方法:
- (BOOL)presentOptionsMenuFromRect:(CGRect)rect
inView:(UIView *)view
animated:(BOOL)animated
Run Code Online (Sandbox Code Playgroud)
并用此方法替换:
- (BOOL)presentOpenInMenuFromRect:(CGRect)rect
inView:(UIView *)view
animated:(BOOL)animated
Run Code Online (Sandbox Code Playgroud)
摘自苹果文档:
此方法类似于 presentOptionsMenuFromRect:inView:animated: 方法,但显示的菜单仅限于能够打开当前文档的应用程序列表。此确定是根据文档类型(如 UTI 属性所示)和已安装的应用程序支持的文档类型来做出的。要支持一种或多种文档类型,应用程序必须使用 CFBundleDocumentTypes 键在其 Info.plist 文件中注册这些类型。
如果没有注册的应用程序支持打开文档,则文档交互控制器不会显示菜单。
此方法异步显示选项菜单。当用户选择适当的选项时,文档交互控制器会自动关闭菜单。您还可以使用missMenuAnimated: 方法以编程方式关闭它。