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. saltstack api安装使用

    Salt自然也是提供api的,使用api对自动化有极大的帮助,我们使用rest风格的api,当然大家都知道salt是python写的,那么自然也就提供了对应的api,但是并不建议使用,因为调用pyth ...

  2. 1.js 模拟a标签打开新网页

    var el = document.createElement("a"); document.body.appendChild(el); el.href = url; //url  ...

  3. java web 学习-网络资源

    [网络收集] 1. JavaWeb学习总结——JSP中的九个内置对象 2. Jsp九大内置对象以及四个作用域 他人学习汇总资源 1. http://www.cnblogs.com/xdp-gacl/t ...

  4. vue的踩坑路

    ------>axios模拟get json一直拿不到文件,先把data放到根目录,再去dev-server.js(就是npm执行的那个文件)里面设置静态资源访问路径app.use('/data ...

  5. angularjs 切换tab页的一个方法

    tab条的 css: .floor-tab-li { float: left; padding: 6px 12px; font-size: 14px; font-weight: normal; lin ...

  6. lightoj 1089 【离散化+线段树】

    题意: 给你n个区间,然后给你m个i点问你这个点在几个所给定的区间里: 思路: 离散化+区间覆盖 #include <bits/stdc++.h> using namespace std; ...

  7. tp5 验证器使用

    路径 app\admin\validate\User.php 如果没有则创建该文件夹和文件 User.php <?php namespace app\junyi\validate; use th ...

  8. ajax 的三种使用方法

    第一种 也是最古老的一种方法之一 from 表单直接提交数据到php文件里 action为路径 <form method="post" action="./inde ...

  9. Unity NGUI学习

    环境 Unity4.3    NGUI v3.68 导入 Project界面->右键->import package->custom package载入安装包即可 untiy4.6用 ...

  10. [Xcode 实际操作]九、实用进阶-(24)使用Segue(页面的跳转连接)进行页面跳转并传递参数

    目录:[Swift]Xcode实际操作 本文将演示使用Segue(页面的跳转连接)进行页面跳转并传递参数. 参照结合:[Xcode10 实际操作]九.实用进阶-(23)多个Storyboard故事板中 ...