IOS學習筆記(八)之UIActivityIndicatorView(活動指標視圖)(部落格地址:http://blog.csdn.net/developer_jiangqq)
Author:hmjiangqq
Email:jiangqqlmj@163.com
UIActivityIndicatorView:
作用:進行提示使用者當前正在載入進度,該控制項可以消除使用者等待的心理事件,增加使用者體驗。
首先來看下官方解說:
Use an activity indicator to show that a task is in progress. An activity indicator appears as a “gear” that is either spinning or stopped.
You control when an activity indicator animates by calling the startAnimating and stopAnimating methods. To automatically hide the activity indicator when animation stops, set the hidesWhenStopped property to YES.
常用的屬性和方法:
- (void)startAnimating; //開始進度動畫
- (void)stopAnimating; //停止進度動畫
- (BOOL)isAnimating; //檢測是否動畫在執行
執行個體代碼:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; // Override point for customization after application launch. self.window.backgroundColor = [UIColor redColor]; UIActivityIndicatorView *activityView=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; activityView.center=CGPointMake(160, 155); [activityView startAnimating]; [self.window addSubview:activityView]; [activityView release]; //定時3s之後,自動停止運行 [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(test:) userInfo:activityView repeats:NO]; [self.window makeKeyAndVisible]; return YES;}-(void)test:(NSTimer *)timer{ UIActivityIndicatorView *view=timer.userInfo; [view stopAnimating]; NSLog(@"進度結束...");}