iOS Loading

在iOS內loading也是很重要的,最重要也是在parser資料的同時給user一點心理準備,當然也可以弄一條processbar來告知用戶,不過我懶,所以就直接弄個loading畫面蓋在畫面最上端,一方面也避免User亂按。

Download code

step1.下載完後的檔案直接解壓縮丟到project內


step2.把檔案匯入.h檔並且把function先預設好
#import <UIKit/UIKit.h>

#import "LoadingView.h"

@interface RootViewController : UITableViewController {
//loading
LoadingView *loading;

}

-(void)initLoading;
-(void)removeLoading;

@end


step3.在.m檔內把initLoading、removeLoading兩個function設定完成
-(void) initLoading{
loading = [[LoadingView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[self.view addSubview:loading];
[loading release];
}

-(void)removeLoading{
// NSLog(@"subView = %@", [self.view subviews]);
for(UIView *subview in [self.view subviews]) {
if([subview isKindOfClass:[LoadingView class]]) {
NSLog(@"remove Loading = %@", subview);
[subview removeFromSuperview];
} else {

}
}
}


step4.完成後就看哪時候需要loading就使用
[self initLoading];

要把他消失使用
[self removeLoading];



Download code

相關連結
iOS Developer Library

沒有留言:

張貼留言