【问题标题】:Adding a UIPickerView over a UITabBarController在 UITabBarController 上添加 UIPickerView
【发布时间】:2010-03-31 20:35:22
【问题描述】:

我正在尝试从屏幕底部(在标签栏顶部)滑动 UIPickerView,但似乎无法显示。动画的实际代码来自 Apple 的示例代码项目之一 (DateCell)。我从标签栏控制器下的第一个视图控制器 (FirstViewController.m) 调用此代码。

- (IBAction)showModePicker:(id)sender {
if (self.modePicker.superview == nil) {
    [self.view.window addSubview:self.modePicker];

    // size up the picker view to our screen and compute the start/end frame origin for our slide up animation
    //
    // compute the start frame
    CGRect screenRect = [[UIScreen mainScreen] applicationFrame];
    CGSize pickerSize = [self.modePicker sizeThatFits:CGSizeZero];
    CGRect startRect = CGRectMake(0.0, screenRect.origin.y + screenRect.size.height, pickerSize.width, pickerSize.height);
    self.modePicker.frame = startRect;

    // compute the end frame
    CGRect pickerRect = CGRectMake(0.0, screenRect.origin.y + screenRect.size.height - pickerSize.height, pickerSize.width, pickerSize.height);

    // start the slide up animation
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];

    // we need to perform some post operations after the animation is complete
    [UIView setAnimationDelegate:self];

    self.modePicker.frame = pickerRect;

    // shrink the vertical size to make room for the picker
    CGRect newFrame = self.view.frame;
    newFrame.size.height -= self.modePicker.frame.size.height;
    self.view.frame = newFrame;
    [UIView commitAnimations];

    // add the "Done" button to the nav bar
    self.navigationItem.rightBarButtonItem = self.doneButton;
}}

只要通过位于 UINavigationBar(全部位于 FirstViewController 下)中的 UIBarButtonItem 触发此操作,则不会发生任何事情。谁能给点建议?

【问题讨论】:

    标签: iphone objective-c uipickerview addsubview


    【解决方案1】:

    原来我错过了一个非常重要的事实,即 UIPickerView 也已在 Interface Builder 中定义......在这样做并连接出口后一切正常!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多