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

    }

    }

  • 相关阅读:
    [loj6039]「雅礼集训 2017 Day5」珠宝 dp+决策单调性+分治
    [loj6038]「雅礼集训 2017 Day5」远行 lct+并查集
    [BZOJ4945][Noi2017]游戏 2-sat
    [BZOJ4942][Noi2017]整数 线段树+压位
    [BZOJ3672][Noi2014]购票 斜率优化+点分治+cdq分治
    12.17模拟赛
    [BZOJ3150][Ctsc2013]猴子 期望dp+高斯消元
    杜教筛
    Swagger展示枚举类型参数
    spring boot 如何映射json格式请求中的枚举值
  • 原文地址:https://www.cnblogs.com/wcLT/p/4753461.html
Copyright © 2020-2023  润新知