High-performance graphics and text frame, the framework of the smooth iOS app-B

Source: Internet
Author: User

About Gallop
Gallop is a powerful, high performance graphics and text mix frame.


Features
Primarily used to address the following requirements:

    • Performance optimizations for scrolling lists. Gallop uses asynchronous drawing, view-level merging, observing Mainrunloop, pre-caching the layout model, and so on, while still maintaining a fairly good scrolling performance when it comes to complex graphics and text blending interfaces (FPS remains at 60).

    • There is a friend circle demo built using gallop in the project.

    • The implementation of text-to-picture interface, such as adding emoticons in the texts, adding a click link to the text. Gallop also provides a convenient way to directly complete the expression, URL link, @ User, #话题 # and other parsing.

    • Easily fillet and obfuscate network pictures and local images, and provide caching, eliminating the need for repetitive processing and optimizing performance.

    • Easily parse HTML rendering to generate native iOS pages. The project is built using Gallop daily demo



Scrolling performance use real machine debugging to see the effect

Demo Snapshot

Modifications
v0.3.5
Lwimagestorage adds an attribute Isblur. When a local picture is processed, the child thread is obfuscated, and when the network picture is processed, the child threads are obfuscated and the blurred version is cached directly. See demo.
v0.3.4

    • Supports coredata to cache layout models

v0.3.3

    • Changed the integration method and resolved the issue of conflict with sdwebimage partial files.

v0.3.2

    • A network picture with a rounded radius is now cached in an extra copy, which solves the problem of too much memory consumption.

v0.3.1

    • When parsing HTML rendering to generate a native iOS page, the picture can be adapted to the height of the original image scale.

v0.3.0

    • Added the ability to parse HTML rendering to generate native iOS pages.

v0.2.5

    • Image loading is optimized.

v0.2.4

    • increased the transactiongroup,lwtransaction,calayer+lwtransaction.

v0.2.3

    • The text adds a stroke drawing mode.

v0.2.2
Added a method

- (void)lw_addLinkForWholeTextStorageWithData:(id)data linkColor:(UIColor *)linkColor highLightColor:(UIColor *)highLightColor;

Abandoned the method

- (id)initWithFrame:(CGRect)frame maxImageStorageCount:(NSInteger)maxCount;

Now, the Lwasyncdisplayview will automatically maintain a reuse pool, you can set a nsstring* type of identifier for Lwstorage, and then use the relevant uiview inside to simplify the API.

    • Fixed a bug that conflicted when adding links to text.

Todo

    • Support for video and audio.

Requirements

    • Using gallop to implement a network picture loading section relies on Sdwebimage ' sdwebimage ', ' ~>3.7 '

    • HTML parsing relies on the LIBXML2 library

Installation

    • Add Libxml2.tbd Library in Xcode's build phases-> Link Binary with libraries

    • Add '/usr/include/libxml2 ' in the Xcode build Setting->header Search paths

    • Installing Sdwebimage

    • Add the. h and. m files under the Gallop folder to your project

    • #import "Gallop.h"

Usage
Api
Quickstart
#import "Gallop.h"


1. Generate a text model

lwtextstorage* textstorage = [[Lwtextstorage alloc] Init];textstorage.text = @ "WAYNEZXCV"; textstorage.font = [UIFont Systemfontofsize:15.0f];textstorage.textcolor = RGB (113, 129, 161, 1);/***   Add click-to-link event for text  ***/[textstorage AddLinkWithData:datainRange:NSMakeRange (0,statusmodel.name.length) Linkcolor:rgb (113, 129, 161, 1) HighlightColor: RGB (0, 0, 0, 0.15)];/***   Click link callback  ***/-(void) Lwasyncdisplayview: (Lwasyncdisplayview *) Asyncdisplayview Didcilickedlinkwithfdata: (ID) data;/***   Replace the text in the specified position with a local image  ***/[textstorage lw_replacetextwithimage:[ UIImage imagenamed:@ "img"]contentmode:uiviewcontentmodescaleaspectfillimagesize:cgsizemake (max.) Alignment: Lwtextattachalignmenttoprange:nsmakerange (webimagetextstorage.text.length-7, 0)];/***   Replace the text in the specified position with a web image  ***/[textstorage lw_replacetextwithimageurl:[nsurl urlwithstring:@ "https://avatars0.githubusercontent.com/ u/8408918?v=3&s=460 "]contentmode:uiviewcontentmodescaleaspectfillimagesize:cgsizemake (at) alignMent:LWTextAttachAlignmentToprange:NSMakeRange (webimagetextstorage.text.length-7, 0)];/***   Replace the text in the specified position with UIView  ***/[textstorage Lw_replacetextwithview:[[uiswitch alloc] Initwithframe:cgrectmake (0, 0, 60.0f, 30.0f)]contentmode:uiviewcontentmodescaleaspectfillsize:cgsizemake (60.0f, 30.0f) alignment: Lwtextattachalignmenttoprange:nsmakerange (1,0)];

2. Create a picture model

/***  本地图片  ***/LWImageStorage* imamgeStorage = [[LWImageStorage alloc] init];imamgeStorage.contents = [UIImage imageNamed:@"pic.jpeg"];imamgeStorage.frame = CGRectMake(textStorage.left, textStorage.bottom + 20.0f, 80, 80);imamgeStorage.cornerRadius = 40.0f;//设置圆角半径/***  网络图片  ***/LWImageStorage* imamgeStorage = [[LWImageStorage alloc] init];imamgeStorage.contents = [NSURL URLWithString:@"https://avatars0.githubusercontent.com/u/8408918?v=3&s=460"];imamgeStorage.frame = CGRectMake(textStorage.left, textStorage.bottom + 20.0f, 80, 80);imamgeStorage.cornerRadius = 40.0f;/***  点击图片回调  ***/- (void)lwAsyncDisplayView:(LWAsyncDisplayView *)asyncDisplayView didCilickedImageStorage:(LWImageStorage *)imageStorage touch:(UITouch *)touch;

3.生成布局模型
LWLayout* layout = [[LWLayout alloc] init];/***  将LWstorage实例添加到layout当中  ***/[layout addStorage:textStorage];[layout addStorage:imamgeStorage];
4.创建LWAsyncDisplayView,并将LWLayout实例赋值给创建LWAsyncDisplayView对象
LWAsyncDisplayView* asyncDisplayView = [[LWAsyncDisplayView alloc] initWithFrame:CGRectZero];asyncDisplayView.layout = layout;[self.view addSubview:asyncDisplayView];
5.解析HTML生成iOS原生页面
/*** Create Lwhtmldisplayview  ***/lwhtmldisplayview* htmlView = [[Lwhtmldisplayview alloc] initWithFrame: SELF.VIEW.BOUNDS];HTMLVIEW.PARENTVC = Self;htmlview.displaydelegate = self; [Self.view addsubview:htmlview];/***   Get lwstoragebuilder  ***/lwstoragebuilder* builder = htmlview.storagebuilder;/***   Create lwlayout  ***/lwlayout* layout = [[Lwlayout alloc] init];/***   Create lwhtmltextconfig  ***/lwhtmltextconfig* contentconfig = [[Lwhtmltextconfig alloc] Init];contentconfig.font = [ Uifont fontwithname:@ "Heiti SC" Size:15.0f];contentconfig.textcolor = RGB (1), Contentconfig.linkcolor = RGB ( 232, 104, 96,1.0f); contentconfig.linkhighlightcolor = RGB (0, 0, 0, 0.35f);/***   Create another lwhtmltextconfig  ***/ lwhtmltextconfig* strongconfig = [[Lwhtmltextconfig alloc] Init];strongconfig.font = [Uifont fontwithname:@] Stheitisc-medium "Size:15.0f];strongconfig.textcolor = [uicolor blackcolor];/***   parsing HTML through XPath and generating lwstorage  ***//***   via UiedgeinsetsSet the layout to pass in the second parameter ***//*** the label name corresponds to the lwhtmltextconfig in the key-value format of the dictionary passed in the last parameter ***/[builder createlwstoragewithxpath:@ "//div[@ class= ' content ']/p "edgeinsets:uiedgeinsetsmake ([Layout suggestheightwithbottommargin:10.0f], 10.0f, 10.0, 10.0f) configdictionary:@{@ "P": contentconfig,@ "strong": strongconfig,@ "em": strongconfig}];/***   Get an array of generated lwstorage instances  ***/nsarray* storages = builder.storages;/***   Add to lwlayout instance  ***/[layout addstorages:storages];/***   Give Lwhtmldisplayview object and assign value  ***/htmlview.layout = layout;
Original address: Http://code4app.com/forum.php?mod=viewthread&tid=10375&extra=page%3D2%26filter%3Dsortid%26orderby %3ddateline%26sortid%3d1

High-performance graphics and text frame, the framework of the smooth iOS app-B

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.