Mo DeJong’s 7 Useful iOS Development SDKs (1)

This article is translated from http://www.modejong.com/iOS/#ex7


Mo DeJong provided 7 interesting sample SDK programs (for Xcode 3.2.5 and iOS 4.2) in his blog. "These programs and prompt information are specially written for developers, but the source code is written with "as-is" "The way is open to the public." I will test these seven SDKs. The author is lazy, but I will give code snippets and screenshots, and if necessary, my modified code. My development environment is Xcode 4.5 + iOS 5.1, and I hope to bring these "old codes" to life.


Table of contents:

(1) Multi-level UITableView

(2) PNG animation

(3) Use ExtendedAudioFile API to read and write CAF format

(4) Use CoreAudio for PCM mixing

(5) AutoPropertyRelease Class (automatically release memory class)

(6) Improve the fade-out effect of CoreAudio

(7)7zip(LZMA)SDK


This blog will mention (1) (2) among them, and the other SDKs will be explained in subsequent blogs. 




Example 1: Multi-level UITableView

"Do you also think that it is a little difficult to use UITableView? I found that there is a convenient way to create a multi-level TableView... but this is only for the case of only text. You can take a look at how the TextTableData class automatically Define a TableView" - This is the situation and solution the author encountered.


   


Source code: TextTableExample.zip (30kb)

It should be noted that compiling and running directly will report an error. The problem is that Xcode 4.5 no longer supports using numerical values ​​to assign values ​​to the NSString class . (The same should be true for other Cocoa classes), so we need to do a conversion:

Legacy code

	for (TextTableElement* ttElement in inElements) {
		label = ttElement.label;
		label += 0x1; // Avoid compiler warning
	}

New version of code

	for (TextTableElement* ttElement in inElements) {
		label = ttElement.label;
        int intLabel = [label intValue];
		intLabel += 0x1; // Avoid compiler warning
        label = [NSString stringWithFormat:@"%d",intLabel];
	}

In this way, the value of NSString can be increased smoothly.


The code runs smoothly. But according to the current "popular standards", it seems that such a design is basically useless. Here we recommend another "multi-level" TableView - the foldable TableView:

http://blog.csdn.net/kmyhy/article/details/5979560 

Also check out a great TableView example from code4app:

http://code4app.com/ios/TableView%E7%9A%84%E5%90%84%E7%A7%8D%E6%93%8D%E4%BD%9C/50bf05986803fa8e5c000001

This example is a pattern used by many apps and is very suitable for organizing TableViews containing large amounts of data.




Example 2: PNG animation

iPhone/iOS does not support the playback of animations in gif format, so continuous playback of animations requires some "curve to save the country" methods. I think most people will choose the more familiar CoreAnimation to continuously playback pictures to achieve the goal. It seems that this classmate Mo DeJong is particularly interested in audio and video processing. He uses MPMoviePlayerController in MediaPlayer.framework. "When you use MPMoviePlayerController, you should want to pull your hair out like me..." The author believes that most of the functions provided by the official API "need to be improved by oneself" in order to play audio and video, and cannot complete what he said "continuously play some PNG image" requirements. MPMoviePlayerController can't handle it, and CoreAnimation will occupy all the memory - what should I do? Let’s look at the author’s example. Playing 30 frames of 480x320 PNG images at 15FPS. I said a lot about CPU performance and audio support later that I don’t understand, so I won’t translate it blindly.


 


Source code: PNGAnimatorDemo.zip (165kb)

This code works fine, and according to the author's description his method only loads the image when it is needed rather than reading all the frames and filling up memory. Let’s first take a look at CoreAnimation’s “cached” method of playing images:

imageView =[[ UIImageView alloc ] initWithFrame : CGRectMake (0, 100, 320, 320)];
imageView . animationImages =images;
[images release ];
imageView . animationDuration =10;
imageView . animationRepeatCount =100;
[ imageView startAnimating ];

The basic idea is to have an NSMutableArray array of images, load the images into images one by one, and then pass them to imageView for continuous playback.

And his method is to repeat this piece of code:

	if ((frame >= animationNumFrames) || (frame < 0))
		return;
	
	NSData *data = [animationData objectAtIndex:frame];
	UIImage *img = [UIImage imageWithData:data];
	imageView.image = img;


It seems that there is not much difference between the two. The animationData here also loads all frames in advance. I think the efficiency improvement mentioned by the author here will not have too obvious effect in the current development environment.




Let’s analyze these two first and continue tomorrow!

===============================================

This article comes from: http://blog.csdn.net/zh405123507

tags:iPhone development iOS development Xcode UITableView CoreAnimation


Guess you like

Origin blog.csdn.net/zh405123507/article/details/8567411