2

Is there a way to rotate an UIPickerView?

4

3 回答 3

3

//放置在视图中的示例代码确实加载了

[super viewDidLoad];
myPicker.delegate = self;
myPicker.dataSource = self;
myPicker.showsSelectionIndicator =YES;
myPicker.backgroundColor = [UIColor blackColor];

CGAffineTransform rotate = CGAffineTransformMakeRotation(3.14/2);

//original settings
//rotate = CGAffineTransformScale(rotate, 0.1, 0.8);

rotate = CGAffineTransformScale(rotate, 0.2, 1.65);
[self.myPicker setTransform:rotate];    

NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:@"155", @"165", @"175", 
                  @"185", @"195", @"205", @"215", nil];
self.pickerData = array; 
[array release];

NSInteger TOTALITEM = [pickerData count];

UILabel *theview[TOTALITEM-1]; // + 1 for the nil
for (int i=1;i<=TOTALITEM-1;i++) {  
 theview[i] = [[UILabel alloc] init];
 theview[i].text = [NSString stringWithFormat:@"%d",i];
 theview[i].textColor = [UIColor blackColor];
 theview[i].frame = CGRectMake(0,0, 25, 25);
 theview[i].backgroundColor = [UIColor clearColor];
 theview[i].textAlignment = UITextAlignmentCenter;
 theview[i].shadowColor = [UIColor whiteColor];
 theview[i].shadowOffset = CGSizeMake(-1,-1);
 theview[i].adjustsFontSizeToFitWidth = NO;

 UIFont *myFont = [UIFont fontWithName:@"Helvetica" size:30];
[theview[i] setFont:myFont];
}


CGAffineTransform rotateItem = CGAffineTransformMakeRotation(-3.14/2);
rotateItem = CGAffineTransformScale(rotateItem, .5, 5);


for (int j=1;j<=TOTALITEM-1;j++) { 
    theview[j].transform = rotateItem;

 }

pickerData = [[NSMutableArray alloc] init];


for (int j=1;j<=TOTALITEM-1;j++) { 
[pickerData addObject:theview[j]];
}
于 2012-10-15T10:01:56.620 回答
2

您可以通过对包含它的视图应用转换来旋转 UIPickerView,就像我在此处的回答中建议的缩放选择器一样。

于 2010-01-31T00:13:53.553 回答
0

你在寻找- (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated吗?

或者您的意思是要将整个控件旋转 90 度,从而使轮子向左和向右旋转?

于 2010-01-29T15:02:51.167 回答