空調屋さん用アプリ「GasCharge」Part2
こんばんは
今回は、前回紹介させていただいた空調屋さん用アプリ「GasCharge」のコードなどを紹介させていただきます。
空調屋さんはITのリテラシーがない方が多く、OSのアップデートをしない方がよくいます。「Swift」で開発するとそういう方が使えない!!て事になりそうなので今回のアプリも「Objective-c」にて開発しております。
アプリ的には、計算機になります。
その中から、よく使用したメソッド、汎用性のあるメソッドを紹介します。
ピッカーが画面下部からアニメーションつけて表示
1 2 3 4 5 6 7 8 9 10 11 12 |
- (void)showPicker { //デバイスの画面サイズを取得 CGRect rect = [[UIScreen mainScreen] bounds]; //ピッカーが下から出るアニメーション [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.2]; [UIView setAnimationDelegate:self]; picker.frame = CGRectMake(0, rect.size.height-300,rect.size.width, 300); [UIView commitAnimations]; } |
ピッカーを画面下部へアニメーションをつけて隠す
1 2 3 4 5 6 7 8 9 10 |
- (void)hidePicker { //デバイスの画面サイズを取得 CGRect rect = [[UIScreen mainScreen] bounds]; //ピッカーを下に隠すアニメーション [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.2]; [UIView setAnimationDelegate:self]; self->picker.frame = CGRectMake(0,rect.size.height,rect.size.width,500); [UIView commitAnimations]; } |
ピッカーに表示させる列数を返す
1 2 3 4 5 |
/*ピッカーに表示させる列数を返す*/ - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView { return 1; } |
ピッカーに表示させる行数を返す
1 2 3 4 5 |
/*ピッカーに表示する行数を返す*/ - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component { return _Modeles.count; } |
ピッカーに表示させる値を返す
例(Models.plist)から値を引っ張っています。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { switch (component) { case 0: // 1列目 return [NSString stringWithFormat:@"%@",_Modeles[(long)row][@"Models"]]; break; default: return 0; break; } } |
て感じです。
汎用できるメッソドが、ピッカー周りしかありませんでした、、
今回は以上になります。