NSOperationQueue     *operationQueue; // for rendering pages on second thread

[operationQueue waitUntilAllOperationsAreFinished];

一句很简单的代码,可以实现UI的异步操作,知道操作完成,才进行进一步刷新。

NSOperationQueue是一个Operation执行队列,你可以将任何你想要执行的Operation添加到Operation Queue中,以在队列中执行。同时Operation和Operation Queue提供了很多可配置选项。Operation Queue的实现中,创建了一个或多个可管理的线程,为队列中的Operation提供可高度自定的执行环境。

DemoCode如下:

// Don't change font feature settings until all secondary thread operations are done

[operationQueue waitUntilAllOperationsAreFinished];

// Set up our font feature bitfield for given optionName

ASDFeaturesBits optionBitSelected = 0;

if (([optionName rangeOfString:ASD_SMALL_CAPITALS]).length > 0 ) {

optionBitSelected = ASDFeaturesSmallCaps;

}

else if (([optionName rangeOfString:ASD_RARE_LIGATURES]).length > 0 ) {

optionBitSelected = ASDFeaturesLigatures;

}

else if (([optionName rangeOfString:ASD_PROP_NUMBERS]).length > 0 ) {

optionBitSelected = ASDFeaturesPropNumbers;

}

else if (([optionName rangeOfString:ASD_STYLISTIC_VARS]).length > 0 ) {

optionBitSelected = ASDFeaturesStylisticVariants;

}

if (optionBitSelected && ((optionBitSelected & ASDFeaturesFeatureMask) != 0)) {

// Font features are most of the time exclusive so for simplicity we allow one feature at a time

viewOptions &= ~ASDFeaturesFeatureMask;

viewOptions |= optionBitSelected;

}

else {

// Passing @"" as the option is used to turn off all options

if ([optionName length] == 0) {

viewOptions = 0;

} else {

viewOptions ^= optionBitSelected;

}

}

if (pageViews[currCoreTextView].selectedFrame == NSUIntegerMax) {

// No selected frame, apply font features to all doc text

NSRange range = NSMakeRange(0, [document.attributedString length]);

[document setFontFeatures:(viewOptions & CoreTextViewOptionsFeatureMask) range:range];

[self relayoutDocFromPage:pageDisplayed];

}

else {

// Apply font features to selected frame

// (note that this only applies for "text" type frames)

CoreTextViewPageInfo* page = [pagesInfo objectForKey:[NSNumber numberWithInt:pageDisplayed]];

CoreTextViewFrameInfo* frame = [page.framesToDraw objectAtIndex:pageViews[currCoreTextView].selectedFrame];

if (frame.frameType == ASDFrameTypeTextFlow) {

[document setFontFeatures:(viewOptions & CoreTextViewOptionsFeatureMask) range:frame.stringRange];

[self relayoutDocFromPage:pageDisplayed];

}

else if (frame.frameType == ASDFrameTypeText) {

ApplyFontFeaturesToString(frame.value, frame.stringRange, (viewOptions & CoreTextViewOptionsFeatureMask));

[frame refreshTextFrame];

[self refreshPage];

}

}

IOS之UI异步刷新的更多相关文章

  1. iOS之UI组件整理

    作者:神兽gcc 授权本站转载. 最近把iOS里的UI组件重新整理了一遍,简单来看一下常用的组件以及它们的实现.其实现在这些组件都可以通过Storyboard很快的生成,只是要向这些组件能够变得生动起 ...

  2. iOS开发UI篇—CAlayer(自定义layer)

    iOS开发UI篇—CAlayer(自定义layer) 一.第一种方式 1.简单说明 以前想要在view中画东西,需要自定义view,创建一个类与之关联,让这个类继承自UIView,然后重写它的Draw ...

  3. iOS开发UI篇—UITabBarController简单介绍

    iOS开发UI篇—UITabBarController简单介绍 一.简单介绍 UITabBarController和UINavigationController类似,UITabBarControlle ...

  4. iOS开发-UI 从入门到精通(三)

    iOS开发-UI 从入门到精通(三)是对 iOS开发-UI 从入门到精通(一)知识点的综合练习,搭建一个简单地登陆界面,增强实战经验,为以后做开发打下坚实的基础! ※在这里我们还要强调一下,开发环境和 ...

  5. iOS开发-UI 从入门到精通(二)

    iOS开发-UI 从入门到精通(二)是对 iOS开发-UI 从入门到精通(一)知识点的巩固,主要以习题练习为主,增强实战经验,为以后做开发打下坚实的基础! ※开发环境和注意事项: 1.前期iOS-UI ...

  6. iOS开发UI篇—懒加载

    iOS开发UI篇—懒加载 1.懒加载基本 懒加载——也称为延迟加载,即在需要的时候才加载(效率低,占用内存小).所谓懒加载,写的是其get方法. 注意:如果是懒加载的话则一定要注意先判断是否已经有了, ...

  7. iOS开发UI篇—CAlayer层的属性

    iOS开发UI篇—CAlayer层的属性 一.position和anchorPoint 1.简单介绍 CALayer有2个非常重要的属性:position和anchorPoint @property ...

  8. iOS开发UI篇—CAlayer(创建图层)

    iOS开发UI篇—CAlayer(创建图层) 一.添加一个图层 添加图层的步骤: 1.创建layer 2.设置layer的属性(设置了颜色,bounds才能显示出来) 3.将layer添加到界面上(控 ...

  9. iOS开发UI篇—CALayer简介

    iOS开发UI篇—CALayer简介   一.简单介绍 在iOS中,你能看得见摸得着的东西基本上都是UIView,比如一个按钮.一个文本标签.一个文本输入框.一个图标等等,这些都是UIView. 其实 ...

随机推荐

  1. web单机优化

    又得开始写博客了,目测又要一周一篇了,当然了这不算python跟前端的,个人喜欢notepad++可惜不能放图片,word什么的太讨厌了 为什么要单机优化呢,很简单,因为不论以后是各类集群也好,物理机 ...

  2. 解决warning: LF will be replaced by CRLF in **(filename)

    使用Windows的Git使用 git add 时出现warning: LF will be replaced by CRLF in **(filename) 原因: CRLF -- Carriage ...

  3. IIS 部署 SSAS

    转自:http://blog.csdn.net/jinjazz/article/details/4058368 1.首先到分析服务器的SQLServer安装目录中找到如下目录和文件 2.然后为IIS建 ...

  4. 爬虫代码实现四:采用Hbase存储爬虫数据(2)

    导入hbase的jar包,在maven仓库找:进入http://mavenrepository.com/,输入hbase client,选择apache hbase client, 点击进入,选择 点 ...

  5. Laravel框架之Request操作

    public function request(Request $request){ //1.取值 //echo $request->input('name'); //echo $request ...

  6. cocos2dx-lua绑定之代码编辑器

    转自:http://blog.csdn.net/wtyqm/article/details/9346863 享受脚本语言灵活.更新方便.免于编译的好处,但也不能忍受离开那些方便的IDE特性(跳转.自动 ...

  7. STL树

    前几天觉得STL中没有树和图真是一种莫大的遗憾啊,但是在网上搜了搜,发现其实可以用容器很简单的构造树. 还是废话少说上代码: struct TreeNode{ DataType data; // Da ...

  8. LeetCode: 448 Find All Numbers Disappeared in an Array(easy)

    题目: Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice an ...

  9. LeetCode: 292 Nim Game(easy)

    题目: You are playing the following Nim Game with your friend: There is a heap of stones on the table, ...

  10. E20180712-hm

    directive n. 指令; <美>命令,训令,指令; 方针;