如何以方向友好的方式在选项卡栏上显示 UIDatePicker?

2024-06-19

我想滑入UIDatePicker当我的用户点击我的表格视图日期字段时,就像在标准联系人应用程序中一样,当用户点击生日字段时。还有一个额外的致命细节:

它位于标签栏应用程序中,我想要UIDatePicker滑过标签栏。当用户将手机横向放置时仍然会旋转。

我展示的方式UIDatePicker是插入视图中,然后为其位置设置动画:

        [self.view addSubview: self.pickerView];

当我这样做时,UIDatePicker显示,但不覆盖选项卡栏。

我还可以将其添加到窗口中:

        [self.view.window addSubview: self.pickerView];

The UIDatePicker正确地滑过选项卡栏,但随后,它不遵循方向。

我发现的唯一半可接受的方法是完全不使用选项卡栏,方法是使用

        detailViewController.hidesBottomBarWhenPushed = YES;

但这不是我想要的:我想要详细视图中的选项卡栏。我只希望它在选择日期时消失。我不能把UIDatePicker在它自己的控制器中hidesBottomBarWhenPushed = YES因为这将完全覆盖屏幕,我宁愿让细节视图仍然部分可见。

欢迎任何建议。

这是我用来展示的完整代码UIDatePicker,从一些示例代码复制而来:

- (void) doPickDate
{
    NSDate *initialDateForPicker = [(ExpenseData*) self.displayedObject displayDate];
    self.pickerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
    self.pickerView.datePickerMode = UIDatePickerModeDate;
    self.pickerView.date = initialDateForPicker;

    // check if our date picker is already on screen
    if (self.pickerView.superview == nil)
    {
        [self.view addSubview: self.pickerView];

        // 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.pickerView sizeThatFits:CGSizeZero];
        CGRect startRect = CGRectMake(0.0,
                                      screenRect.origin.y + screenRect.size.height,
                                      pickerSize.width, pickerSize.height);
        self.pickerView.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.pickerView.frame = pickerRect;

        // shrink the table vertical size to make room for the date picker
        CGRect newFrame = self.tableView.frame;
        newFrame.size.height -= self.pickerView.frame.size.height - 49 /* tab bar height */;
        self.tableView.frame = newFrame;
        [UIView commitAnimations];

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

}

您应该设置UIDatePicker对象作为inputView该特定文本字段的。所有动画和演示内容都将得到处理。

隐藏光标

没有方法可以隐藏光标。我能想到的唯一机制是使用leftView属性并将其设置为标签。

CGRect frame = self.textField.bounds;

UILabel * theLabel = [[[UILabel alloc] initWithFrame:frame] autorelease];
theLabel.userInteractionEnabled = YES;
theLabel.backgroundColor = [UIColor clearColor];

UITapGestureRecognizer * tap = [[[UITapGestureRecognizer alloc] initWithTarget:self
                                                                        action:@selector(tap:)] autorelease];
[theLabel addGestureRecognizer:tap];

self.textField.leftViewMode = UITextFieldViewModeAlways;
self.textField.leftView = theLabel;
self.textField.clipsToBounds = YES;

并使用以下方法处理水龙头,

- (void)tap:(UIGestureRecognizer *)gesture {
    [self.textField becomeFirstResponder];
}

现在,这不适用于圆角矩形按钮,因为无论标签的框架是什么,光标都会在右角闪烁。它隐藏其他边框样式的光标。您还可以通过将值设置为其文本来充分利用该标签。

UILabel * theLabel = textField.leftView;
theLabel.text = @"Appropriate Value from Picker";
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何以方向友好的方式在选项卡栏上显示 UIDatePicker? 的相关文章

  • 您是否标记 UIView 或将它们保留为属性?

    这主要是一个风格问题 但自从我开始为 iPhone 编程以来 我一直很好奇其他人的想法是什么 当您的 iPhone 应用程序中有一个 UIView 并且需要在应用程序的其他位置访问它时 通常在视图控制器中的另一个函数中 您是否喜欢用整数标记
  • ios 用户如何取消 Facebook 登录?

    当用户到达此屏幕时 无法取消 我能做些什么 为了首先获得这个视图 我正在运行 NSMutableDictionary params NSMutableDictionary dictionaryWithObjectsAndKeys vid l
  • NSNotificationCenter 为“观察者”和“对象”保留什么类型的引用?

    任何人都可以澄清 阐明有关情况 NSNotificationCenter addObserver selector name object 观察者 和 对象 参数的通知中心保留哪些类型的引用 从通知中心删除观察者的最佳实践是什么 多线程应用
  • 使用 iOS 7 检索设备 WiFi MAC 地址

    我们的应用程序使用设备 WiFi MAC 地址来唯一标识设备 根据苹果文档 https developer apple com news id 8222013a我们将开始使用 UIDevice 的identifierForVendor 属性
  • 如何以方向友好的方式在选项卡栏上显示 UIDatePicker?

    我想滑入UIDatePicker当我的用户点击我的表格视图日期字段时 就像在标准联系人应用程序中一样 当用户点击生日字段时 还有一个额外的致命细节 它位于标签栏应用程序中 我想要UIDatePicker滑过标签栏 当用户将手机横向放置时仍然
  • UITableView:显示 tableFooterView 时运行代码?

    我正在使用 UIView表页脚视图 http developer apple com library ios documentation uikit reference UITableView Class Reference Referen
  • iPhone 上的双精度与浮动

    我刚刚听说 iPhone 本身无法进行双倍操作 从而使它们比常规浮动慢得多 这是真的 证据 我对这个问题很感兴趣 因为我的程序需要高精度计算 而且我将不得不在速度上妥协 iPhone 可以在硬件中执行单精度和双精度算术 在 1176 原始
  • 如何使用 iPhone 将照片上传到服务器?

    我正在编写一个 iPhone 应用程序 它可以拍摄照片然后将其上传到服务器 如何使用 Cocoa 将照片上传到服务器 我想我在某处使用 NSUrl Thanks Header interface EPUploader NSObject NS
  • 如何在代码中编辑约束

    我有一个以 100 开始宽度限制的网页 当用户单击按钮时 我想将约束更改为 200 我试过这个 NSLayoutConstraint constrain NSLayoutConstraint constraintWithItem self
  • 隐藏选项卡栏项目并对齐其他选项卡项目

    在我的应用程序中 我有 4 个选项卡栏项目 我正在 XIB 文件中添加这 4 个选项卡栏项目 最初我必须显示 3 个选项卡栏项目 同步后我必须在我的应用程序中显示第 4 个选项卡栏项目 因此 为此 我使用以下代码隐藏第四个选项卡栏项目 se
  • MKAnnotationView 是否缓冲其输入队列?

    我想根据它们代表的相对时间在 UIMapView 中显示不同颜色的图钉但似乎 mapView viewForAnnotation 方法只做与调用时间无关的事情 在我的代码示例中 我已经从文件中检索了较早和较新的位置到 self fileAr
  • 在 Objective-c 中使用 NSDate 获取昨天

    我需要使用 NSDate 对象获取昨天的日期 任何想法 编辑 已解决 NSDate yesterday NSDate dateWithTimeIntervalSinceNow 86400 试试这个代码 通过这种方式 您可以获得接下来的几天
  • 按钮点击事件是否会被点击手势识别器覆盖?

    我有一个按钮 如果点击该按钮以外的任何内容 我想让该按钮消失 所以我为删除按钮设置了 target action self deleteButton addTarget self action selector deleteButtonTa
  • NSProxy 如何“将自身转变为另一个对象”?

    The NSProxy 类参考 http developer apple com library mac documentation Cocoa Reference Foundation Classes NSProxy Class Refe
  • 如果 [super init] 返回 nil 为什么不抛出异常?

    这被认为是典型的 id init self super init if self lt initializations gt return self 但选择这样的实际上能做出适当响应的东西不是更好吗 id init self super i
  • 在 IOS 上检查 Facebook Connect 会话

    在新的 Facebook 库中 FBSession 对象消失了 当用户启动应用程序时 如何在不提示 safari 或 uiwebview 的情况下立即检查用户的设备上是否有有效会话 facebook isSessionValid 方法适用于
  • 多对多关系中的 KVO 对象属性

    我有一个核心数据对多关系 由父 gt 子组成 我想设置一个键值观察机制 以便当任何子对象上的属性 例如 firstName lastName 发生更改时 它会触发通知 使用标准 KVO 语法时 self parentObject addOb
  • 没有jquery的动画,左右滑动

    我试图在显示 div 时将其向左滑动 在隐藏它时将其向右滑动 但我不想使用 jQuery 有没有一种方法可以在不使用javascript库的情况下制作简单的动画并支持IE7和IE8 这是我的显示 隐藏js function showHide
  • SplitViewController 与 TabbarController

    我在我的应用程序中使用分割视图功能 我必须将选项卡栏放在 rootViewController 中 但是 当我在选项卡栏中添加控制器并将它们添加到分割视图中时 它不会分割 它只显示detailViewController 这是应用程序中完成
  • 当点击 UITableViewCell 的子视图时引发选择事件 (didSelectRowAtIndexPath)

    我创建了一个自定义 UITableViewCell 其中包含许多子视图 在大多数情况下 我希望 UITableViewCell 的控制器来处理事件 在一种情况下 我希望子视图简单地将事件传递给父 UITableViewCell 这将导致它在

随机推荐