iOS文档浏览与文件夹的状态变化的监听

5 篇文章 0 订阅
1 篇文章 0 订阅

iOS下的文档浏览以前采用过webview来实现,今天在无意中发现了QuickLook这个框架,是在SDK 3.2中添加的,看了下提供文档预览功能,实际效果类似于webview的展示效果,官方的例子为DocInteraction,其中代码中提到有三种方式:

// three ways to present a preview:

   // 1. Don't implement this method and simply attach the canned gestureRecognizers to the cell

    //

   // 2. Don't use canned gesture recognizers and simply use UIDocumentInteractionController's

   //      presentPreviewAnimated: to get a preview for the document associated with this cell

    //

   // 3. Use the QLPreviewController to give the user preview access to the document associated

   //      with this cell and all the other documents as well.

这段话中的方法1看代码应该是指通过在长按时间出发打开动作,其他两个就是两种显示预览的方式,其中一段求文件大小的代码以后可以用用:

if (size == 0) 
		formattedStr = @"Empty";
	else 
		if (size > 0 && size < 1024) 
			formattedStr = [NSString stringWithFormat:@"%qu bytes", size];
        else 
            if (size >= 1024 && size < pow(1024, 2)) 
                formattedStr = [NSString stringWithFormat:@"%.1f KB", (size / 1024.)];
            else 
                if (size >= pow(1024, 2) && size < pow(1024, 3))
                    formattedStr = [NSString stringWithFormat:@"%.2f MB", (size / pow(1024, 2))];
                else 
                    if (size >= pow(1024, 3)) 
                        formattedStr = [NSString stringWithFormat:@"%.3f GB", (size / pow(1024, 3))];
还有一个类叫 DirectoryWatcher ,用于监视目录下文件删除或新增变化的,这个还是蛮不错的,可以学些下


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值