2013年12月23日月曜日

012-ロード中にぐるぐる回すインディケーター( UIActivityIndicatorView, UIActivityIndicatorViewStyleWhiteLarge)

ロード中や読み込み時に表示するグルグル回すインディケ−タの使い方を記述します。

■生成
UIActivityIndicatorView* indicator = [[UIActivityIndicatorView alloc] init];

■オブジェクトの場所を指定
[indicator型 setFrame:CGRectMake(0, 0, 100, 100)];

■くるくる回す
[indicator型 startAnimating];

■くるくる回さない
[indicator型 stopAnimating];

■回っているかの判定
[indicator型 isAnimating
返し値はBOOL値

■ぐるぐるが回っていない時にぐるぐるを非表示時にするかの設定
[indicator型 setHidesWhenStopped:(BOOL)]
YES,NOで設定。true falseでは駄目だった

■ぐるぐる停止時の表示を取得
[indicator型 hidesWhenStopped]
返し値はBOOL値

■ぐるぐるの大きさの指定
indicator型.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;

定数
UIActivityIndicatorViewStyleWhiteLarge
白色、大きめ

UIActivityIndicatorViewStyleWhite
白色

UIActivityIndicatorViewStyleGray
灰色



■サンプルソース
#import "ViewController.h"

@interface ViewController (){
    // アクティビティインジケータ変数
    UIActivityIndicatorView* indicatorLarg;
}

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    //画面背景を黒色にする
    [self.view setBackgroundColor:[UIColor blackColor]];

    //ぐるぐる回るポジション
    CGRect rect                            = CGRectMake(0, 0, 100, 100);
    
    //ぐるぐる回るインディケータの生成
    indicatorLarg = [[UIActivityIndicatorView alloc]initWithFrame:rect];
    
    // アクティビティインジケータのスタイルをセット :今回は大きめのサイズ
    indicatorLarg.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
    
    // くるくるをまわす
    [indicatorLarg startAnimating];
    // UIActivityIndicatorViewのインスタンスをビューに追加
    [self.view addSubview:indicatorLarg];
    
    //タッチジェスチャーを取得
    UITapGestureRecognizer* tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
    //タッチジェスチャーをビューに設定
    [self.view addGestureRecognizer:tapRecognizer];
}

//タッチされた時の判定
- (void)handleTapGesture:(UITapGestureRecognizer *)sender {
    //ぐるぐる回っているかの判定
    if ( [indicatorLarg isAnimating] ){
        //ぐるぐるSTOP!!
        [indicatorLarg stopAnimating];
        
        //ぐるぐるSTOP時に隠すか止まったままにするか
        bool bIsHide = [indicatorLarg hidesWhenStopped];
        [indicatorLarg setHidesWhenStopped:!bIsHide];
        
    }else{
        //ぐるぐる回っていなかったら、回す
        [indicatorLarg startAnimating];
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end


■実行結果


こんな感じになります。

タッチすると、ぐるぐるが止まって、
もう一回タッチすると動きだします。


このロード中のぐるぐるの正式名称は何て言うんですかね??