IOS image cache playback

Source: Internet
Author: User

Imagecache. h

//

// Imagecache. h

// Nowlearn

//

// Created by Wang doublejie on 12-9-12.

// Copyright (c) 2012 _ mycompanyname _. All rights reserved.

//

// Image cache class

# Import <Foundation/Foundation. h>

@ Interface imagecache: nsobject

{

}

+ (Uiimage *) LoadImage :( nsstring *) imagename;

+ (Void) releasecache;

@ End

Imagecache. m

//

// Imagecache. m

// Nowlearn

//

// Created by Wang doublejie on 12-9-12.

// Copyright (c) 2012 _ mycompanyname _. All rights reserved.

//

# Import "imagecache. H"

@ Implementation imagecache

Static nsmutabledictionary * dict;

+ (Uiimage *) LoadImage :( nsstring *) imagename

{

If (! Dict) dict = [nsmutabledictionary
Dictionary] retain];

Uiimage * image = [dict
Objectforkey: imagename];

If (! Image ){

Nsstring * ImagePath = [[nsbundle
Mainbundle] pathforresource: imagename
Oftype: Nil];

Image = [uiimage imagewithcontentsoffile: ImagePath];

If (image ){

[Dict setobject: Image
Forkey: imagename];

}

}

Return image;

}

+ (Void) releasecache

{

If (dict ){

[Dict removeallobjects];

}

}

@ End

// Use

-(Void) viewdidload

{

[Super
Viewdidload];

Nsmutablearray * images = [nsmutablearray
Alloc] initwithcapacity: 30];

For (INT I = 1; I <= 9; I ++ ){

Nsstring * imagename = [nsstring
Stringwithformat: @ "page_0000d.jpg", I];

Uiimage * image = [imagecache
LoadImage: imagename];

[Images addobject: Image];

}

Imageview = [[uiimageview
Alloc] initwithframe: cgrectmake (0,100,320,320)];

Imageview. animationimages = images;

[Images release];

Imageview. animationduration = 10;

Imageview. animationrepeatcount = 100;

[Imageview startanimating];

[Self. View
Addsubview: imageview];

Uibutton * BTN = [uibutton
Buttonwithtype: uibuttontyperoundedrect];

BTN. Frame = cgrectmake (30,420, 90, 35 );

[BTN settitle: @ "clear memory usage" forstate: uicontrolstatenormal];

[BTN settitle: @ "clear memory usage" forstate: uicontrolstatehighlighted];

[BTN addtarget: Self
Action: @ selector (clearmemory :)
Forcontrolevents: uicontroleventtouchupinside];

[Self. View
Addsubview: BTN];

// Do any additional setup after loading the view.

}

Related Article

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.