zoukankan      html  css  js  c++  java
  • IOS之UI异步刷新

    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];

    }

    }

  • 相关阅读:
    关于机器人流量对抗的一点感想
    保卫"木叶",从火影剧情看网站攻防的演变
    自动化工具层级图
    对抗恶意机器人/自动化行为的新思路与方案
    C++ 数组、链表和二叉树的比较
    #ifndef和#define区别
    xavier上安装teamviewer
    Ubuntu16.04 下有关conda虚拟环境的一些使用方法
    vector中push_back和emplace_back的区别
    int、int16、int32、int64、float、float16、float32、float64
  • 原文地址:https://www.cnblogs.com/wcLT/p/4753461.html
Copyright © 2011-2022 走看看