如何更改 uipickerview 横向?
我在这里开发应用程序。我无法在横向模式下更改pickerview。这是我的代码。
-(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;
}
在我的应用程序中,我创建的肖像模式运行良好。但是当我尝试在横向模式下编写代码时,它可能会错误定位。我怎样才能做到这一点。 我如何更改横向模式。任何人都可以帮助我。提前致谢。
Here i developing application. I could not change pickerview in landscape mode. Here is my code.
-(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;
}
In my application i created portrait mode ran fine. But when i try to write code in landscape mode it can positioned wrongly. How can i do this.
How can i change landscape mode. Anybody help me. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只需设置尺寸检查器属性,如下所示:
PS 编辑 1:您必须在
编辑2:
中返回yes:如果您这样做,则不需要检查方向的条件并为其制作框架。
You just need to set size inspector attributes like this:
P.S. Edit 1:You have to return yes in
Edit 2:
If you are doing like this you don't need if condition for checking orientation and make frame for it.