非常に少数のiPhoneアプリでしか見たことがありません...しかし、(上/下ではなく)左/右に回転するピッカーのように見えます。
彼らは通常、それをtableViewの1行に配置します...ユーザーが少数の選択肢(3〜10など)からすばやく選択できるようにします。
それはどのようにコード化されていますか?
非常に少数のiPhoneアプリでしか見たことがありません...しかし、(上/下ではなく)左/右に回転するピッカーのように見えます。
彼らは通常、それをtableViewの1行に配置します...ユーザーが少数の選択肢(3〜10など)からすばやく選択できるようにします。
それはどのようにコード化されていますか?
Dave DeLongによる回答を続けると、このように機能するようになりました......
viewDidLoad
私はこれをしました...
CGRect frame = horizontalPickerView.frame;
frame.size.width = 50;
frame.size.height = 216;
frame.origin.x=90;
frame.origin.y = 200;
horizontalPickerView.frame = frame;
horizontalPickerView.transform = CGAffineTransformMakeRotation(3.14159/2);
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
UILabel *lbl = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 30, 20)] autorelease];
lbl.transform = CGAffineTransformMakeRotation(-3.14159/2);
lbl.text = @"hi";
return lbl;
}
お役に立てれば
これを行うには、通常の UIPickerView を取得し、その幅を ( 経由でsetFrame:
) 調整してから、NSAffineTransform を適用して 90 度回転させます。次に、ピッカー内の各アイテムを反対方向に 90 度回転させる必要があります。
適切に行うのは少し面倒ですが、行うことはできます。
@Madhupのコードは、水平方向を検索したときに私が望んでいた一般的な方向に私を導きましたがUIPickerView
、左から右への回転に対するより適切な答えを探していた人にとって、尋ねられた質問は実際には扱われていないことに気付きました。私が読んだ回答のコードはすべて、左から右へのスワイプを有効にするためのものであり、ピッカーはより高い値のラベル/行をビューの左側にプッシュしました。ここに私の貢献があります:
viewDidLoad
メソッドでは:
yourPickerView.frame = frame;
yourPickerView.transform = CGAffineTransformMakeRotation(4.71238898); //Instead of rotating clockwise 90° we're rotating 90° counterclockwise. 4.71238898 being ≈270° in radians.
[self.view addSubview:self.picker];
self.yourPickerView.delegate = self;
self.yourPickerView.dataSource = self;
self.yourPickerView.showsSelectionIndicator = YES;
self.yourPickerView.userInteractionEnabled = YES;
のpickerView
方法:
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 20, 20)] autorelease];
yourLabel.transform = CGAffineTransformMakeRotation(1.57079633); //Instead of rotating counterclockwise 90° we're rotating 90° clockwise 1.57079633 being ≈90° in radians.
yourLabel.font = [UIFont fontWithName:@"System-Bold" size:18]; //Your font here.
yourLabel.text = @"yourLabel's text"; //or like me [NSString stringWithFormat:@"%@, [yourArray objectAtIndex:row]]
yourLabel.backgroundColor = [UIColor clearColor];
return label;
}
これを試してください->UIPickerviewのサイズのプレーンUIVewを作成し、それにピッカーを追加します。numberOfComponentsInPickerView=1を設定します。コンポーネントの幅を設定します。次に、小さなサブビューを追加して、残りのピッカーを非表示にします。コンポーネントの回転ホイールのみが表示されます。プレーンビューを変換して、90度回転させます。
次の場所で変換を適用してください。
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
UILabel *lbl = nil;
if(view)
{
lbl = (UILabel *) [view viewWithTag:11];
}
else
{
view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 32, 32)];
lbl = [[UILabel alloc] initWithFrame:CGRectMake(1, 0, 30, 30)];
lbl.tag = 11;
lbl.backgroundColor = [UIColor clearColor];
lbl.textAlignment = UITextAlignmentCenter;
lbl.font = [UIFont fontWithName:@"Helvetica-Bold" size:18];
lbl.transform = CGAffineTransformRotate(lbl.transform, M_PI +M_PI/2);
[view addSubview:lbl];
[lbl release];
}
lbl.text = [dataSourceArray objectAtIndex:row];
return view;
}
これで、任意のビューの水平ピッカーのサブビューとしてペイリンビューを追加できます。
必要なアイテムをページごとに 1 つ持つページ付きスクロールビューを試してください。コントロールのグラフィックを改善したい場合は、その上に画像をオーバーレイし、水平スクロールのみを許可します (スクロールビューの contentSize を実際のビューのサイズを調整し、コントロールでの垂直スクロールのバウンスを無効にします)。
独自のサイズのピッカーを作成できるように、プログラムでピッカーを作成する必要があります。CGRectMake(x, y, width, height)
回転させる必要がありますが、ピッカーの dataSources メソッドでも回転させると、ビューをピッカーの回転とは逆に回転させる必要があります。 、うまくいけばコードを含めています
.....
...
...
NSArray *arr = [NSArray arrayWithObjects:@"1 mi", @"2 mi", @"5 mi", @"10 mi", @"15 mi", @"20 mi", @"25 mi",
@"30 mi", @"35 mi", @"40 mi", @"45 mi", @"50 mi", @"75 mi", @"99 mi", nil];
radiusDefaults = [[NSMutableArray alloc] initWithArray:arr] ;
radiusPicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 0, 100, 150)];
radiusPicker.delegate = self;
radiusPicker.dataSource = self;
radiusPicker.showsSelectionIndicator = NO;
//Resize the picker, rotate it so that it is horizontal and set its position
CGAffineTransform rotate = CGAffineTransformMakeRotation(-1.57);
rotate = CGAffineTransformScale(rotate, .1, .5);
CGAffineTransform t0 = CGAffineTransformMakeTranslation(-61, 0);
radiusPicker.transform = CGAffineTransformConcat(rotate,t0);
// [theNavigationBar.topItem setTitleView:radiusPicker] ;
UIView *pickerWrapper = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 215)];
[self.view addSubview:radiusPicker];
[radiusPicker selectRow:6 inComponent:0 animated:NO];
[radiusPicker release];
.....
.......
....
#pragma mark -
#pragma mark UIPickerView
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row
forComponent:(NSInteger)component reusingView:(UIView *)view{
UIView *viewForRow = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 70, 400)] autorelease];
UILabel *label;
UIFont *font = [ UIFont fontWithName:@"ArialRoundedMTBold" size:22];
label = [[[UILabel alloc] initWithFrame:CGRectMake(0, 20, 70, 350)] autorelease];
[label setText:[NSString stringWithFormat:@"%@", [radiusDefaults objectAtIndex:row]]];
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor blueColor];
label.font = font;
label.backgroundColor = [UIColor clearColor];
// label.opaque = NO;
[viewForRow addSubview:label];
CGAffineTransform rotate = CGAffineTransformMakeRotation(1.57);
rotate = CGAffineTransformScale(rotate, 1, 6.5);
[viewForRow setTransform:rotate];
return viewForRow;
}
テーブル ビューを回転させようと考えたことはありますか?
そうは思いませんでした。それを試してみてください。:)