如何更改横向uipickerview?
问题描述:
这里我正在开发应用程序。我无法在横向模式下更改pickerview。这是我的代码。如何更改横向uipickerview?
-(IBAction) showPicker:(UIControl *)sender
{
UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:@""
delegate:self
cancelButtonTitle:@"Done"
destructiveButtonTitle:nil
otherButtonTitles:nil];
menu.tag=1;
UIPickerView *pickerView;
if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
self.interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(-80,70,220,0)];
pickerView.delegate = self;
pickerView.dataSource = self;
pickerView.showsSelectionIndicator = YES;
[menu addSubview:pickerView];
[menu showInView:self.view.superview];
[menu setBounds:CGRectMake(0,0,320, 470)];
[pickerView release];
[menu release];
NSLog(@"Landscape");
}
else
{
NSLog(@"Portrait");
pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0,70,220,0)];
pickerView.delegate = self;
pickerView.dataSource = self;
pickerView.showsSelectionIndicator = YES;
[menu addSubview:pickerView];
[menu showInView:self.view.superview];
[menu setBounds:CGRectMake(0,0,320, 470)];
[pickerView release];
[menu release];
}
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return [arrayNo count];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
[entered2 resignFirstResponder];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
entered2.text=[arrayNo objectAtIndex:row];
[entered2 resignFirstResponder];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [arrayNo objectAtIndex:row];
}
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
{
int sectionWidth = 300;
return sectionWidth;
}
在我的应用程序中,我创建的肖像模式运行良好。但是当我尝试在横向模式下编写代码时,它可能定位错误。我怎样才能做到这一点。 如何更改横向模式。任何人都可以帮助我。提前致谢。
答
你只需要设置大小检查属性是这样的:
附: 编辑1:你必须在
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
编辑2是返回:
如果你正在做这样你就不需要,如果条件检查方向,使框架它。
我有横向模式的选择器的问题,并解决它与此stackoverflow后:http://stackoverflow.com/questions/1088163/loading-a-uidatepicker-in-landscape-on-a-uinavigationcontroller看看是否这有助于。 – chris