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

    }

    }

  • 相关阅读:
    递归函数及Java范例
    笔记本的硬盘坏了
    “References to generic type List should be parameterized”
    配置管理软件(configuration management software)介绍
    WinCE文件目录定制及内存调整
    使用Silverlight for Embedded开发绚丽的界面(3)
    wince国际化语言支持
    Eclipse IDE for Java EE Developers 与Eclipse Classic 区别
    WinCE Heartbeat Message的实现
    使用Silverlight for Embedded开发绚丽的界面(2)
  • 原文地址:https://www.cnblogs.com/wcLT/p/4753461.html
Copyright © 2011-2022 走看看