将“完成”按钮添加到 iPhone 上的唯一数字键盘

2023-11-29

我使用下面这个方便的代码成功地将完成按钮添加到我的数字键盘。但我有一个启动 MFMailComposeViewController 的电子邮件按钮。如何确保完成按钮不会出现在电子邮件键盘上?

//
//  UIViewController+NumPadReturn.m
//  iGenerateRandomNumbers
//
//  Created by  on 12/4/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "UIViewController+NumPadReturn.h"


@implementation UIViewController (NumPadReturn)

-(void) viewDidLoad{
    // add observer for the respective notifications (depending on the os version)
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) {
        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(keyboardDidShow:) 
                                                     name:UIKeyboardDidShowNotification 
                                                   object:nil];     
    } else {
        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(keyboardWillShow:) 
                                                     name:UIKeyboardWillShowNotification 
                                                   object:nil];
    }

}


- (void)keyboardWillShow:(NSNotification *)note {
    // if clause is just an additional precaution, you could also dismiss it
    if ([[[UIDevice currentDevice] systemVersion] floatValue] < 3.2) {
        [self addButtonToKeyboard];
    }
}

- (void)keyboardDidShow:(NSNotification *)note {
    // if clause is just an additional precaution, you could also dismiss it
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) {
        [self addButtonToKeyboard];
    }
}

- (void)addButtonToKeyboard {
    // create custom button
    UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
    doneButton.frame = CGRectMake(0, 163, 106, 53);
    doneButton.adjustsImageWhenHighlighted = NO;
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.0) {
        [doneButton setImage:[UIImage imageNamed:@"DoneUp3.png"] forState:UIControlStateNormal];
        [doneButton setImage:[UIImage imageNamed:@"DoneDown3.png"] forState:UIControlStateHighlighted];
    } else {        
        [doneButton setImage:[UIImage imageNamed:@"DoneUp.png"] forState:UIControlStateNormal];
        [doneButton setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted];
    }
    [doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];
    // locate keyboard view
    UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
    UIView* keyboard;
    for(int i=0; i<[tempWindow.subviews count]; i++) {
        keyboard = [tempWindow.subviews objectAtIndex:i];

        // keyboard found, add the button
        if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) {
            if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES)
                [keyboard addSubview:doneButton];
        } else {
            if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
                [keyboard addSubview:doneButton];
        }
    }


}

- (void)doneButton:(id)sender {
    NSLog(@"doneButton");
    [self.view endEditing:TRUE];
}



@end

我正在尝试扩展 UIViewController,以便在导入此子类时它会自动执行此操作,因此我的应用程序中的布尔标志可能不起作用。


对于 iOS 3.2+,无论如何,你不应该再使用这个 hack。相反,将您的自定义视图分配给您的控件inputAccessoryView财产。

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

将“完成”按钮添加到 iPhone 上的唯一数字键盘 的相关文章

  • 有没有办法使用 openURL 将 pin 放入 google 地图 iphone 应用程序中?

    我想创建一个 iPhone 应用程序 可以打开谷歌地图应用程序并在地图上放置图钉 我有图钉的确切位置 由其经度和纬度指定 我还有一个引脚名称 例如 位置 1 应与图钉一起显示 我知道 UIApplication openURL 可用于此目的
  • iOS 应用程序和.NET 应用程序之间的通信?

    我有 2 个应用程序 一个是 iOS 应用程序 一个是 NET 应用程序 我希望我的 iOS 应用程序发送一条消息 调用 NET 应用程序的方法 将一些字符串发送到 NET 应用程序以保存到数据库 那么 我的 iOS 应用程序如何与 NET
  • locationManager:didRangeBeacons 方法未检测到 BLE 设备

    我正在使用 Nordic BLE nRF8001 开发套件来测试 CoreBluetooth 使用 CBCentralManager 的方法 例如 didDiscoverPeripheral didConnectPeripheral 等 我
  • 如何以编程方式设置 iOS 6/7 Delta

    当我离开 iOS6 时 我正在使用 Xcode 4 6 开发 UISplitView 应用程序 我有设计 现在我迁移到新的 Xcode5 现在我有这样的设计 UINavigationBar 完全重叠我的 UISearchBar Leo Na
  • 从 iPhone 上的 NSString 中删除 HTML 标签

    有几种不同的方法可以删除HTML tags从一个NSString in Cocoa One way http cocoa karelia com Foundation Categories NSString Flatten a string
  • object_setClass()而不是分配isa指针的性能

    我注意到在 XCode 4 6 的最新更新中 我收到了关于以下几行的警告JSONKit m 具体来说 设置对象类的行 dictionary gt isa JKDictionaryClass 这些被标记为已弃用 并注明首选方法是使用objec
  • Swift 和 Objective-C 框架公开其内部结构

    我正在尝试将 Swift 添加到具有公共 私有和项目文件的现有 Objective C 框架中 为了让 Swift 能够访问项目文件 我添加了一个定义新模块的模块映射 例如MyFramework Internal 通过包含所有项目标题 如下
  • 带有内容矩形抖动的核心动画

    在我的 益智 游戏中 这些碎片是使用CALayer对于每件作品 有 48 块 在 8x6 网格中 每块为 48x48 像素 我不确定这是否是太多层 但如果这不是最好的解决方案 我不知道什么是 因为使用 Quartz2D 每帧重新绘制整个显示
  • 如何阻止我的应用程序设置“隔离”位?

    从 OS X 10 7 3 开始 我的文本编辑器就在它接触的任何文件上设置 隔离 位 我的文本编辑器设计用于处理 shell 脚本 如果设置了隔离位 则无法从命令行执行 shell 脚本 直到您在 Finder 中双击它并浏览 此应用程序是
  • 当点击 UITableViewCell 的子视图时引发选择事件 (didSelectRowAtIndexPath)

    我创建了一个自定义 UITableViewCell 其中包含许多子视图 在大多数情况下 我希望 UITableViewCell 的控制器来处理事件 在一种情况下 我希望子视图简单地将事件传递给父 UITableViewCell 这将导致它在
  • 如何在 iPhone 应用程序的 url 中传递字符串值

    NSURLRequest request NSURLRequest requestWithURL NSURL URLWithString http www krsconnect no community api html method ba
  • 我如何知道 UITableView 何时完成 ReloadData?

    我试图在执行完成后滚动到 UITableView 的底部 self tableView reloadData 我原本有 self tableView reloadData NSIndexPath indexPath NSIndexPath
  • 使用捏合手势;如何放大用户手指实际“捏”的位置?

    我已经在我的应用程序中的 UIImageView 上实现了 UIPinchGestureRecognizer 但是无论我在图像的哪个位置捏合 它似乎都会放大到同一个位置 有谁知道我如何让它放大到用户实际 捏 的地方 请参阅下面的代码 视图控
  • 从 NSString 的第一行删除换行符

    我怎样才能删除第一个 nNSString 中的字符 编辑 只是为了澄清一下 我想做的是 如果字符串的第一行包含 n 字符 请将其删除 否则不执行任何操作 即 如果字符串是这样的 nhello this is the first line n
  • UIAlertView 中的 MPVolumeView?

    是否可以将 MPVolumeView 放入 UIAlertView 中 我已经尝试过put它在里面 但不显示 这可能是sizeToFit or initWithFrame 部分 有没有办法测试是否MPVolumeView实际上正在被创建吗
  • 取消交互式 UINavigationController 弹出手势不会调用 UINavigationControllerDelegate 方法

    如果拖动 a 的边缘UIViewController开始交互式流行过渡UINavigationController the UIViewController在电流下方有viewWillAppear 调用 然后是UINavigationCon
  • UICollectionviewcell 更改背景

    如果我知道部分编号和项目编号 如何更改单元格中的背景 下面的代码显示了我如何尝试做到这一点 UICollectionViewCell collectionView UICollectionView collectionView cellFo
  • 拦截传入短信

    我想知道拦截短信的选项有哪些 我希望能够在收到短信时启动一些代码来处理短信 任何关于这在技术上是否可行以及如果有不止一种方法我有什么选择的建议 将不胜感激 谢谢 保罗 由于您有如此多的标签 因此很难判断您实际上是为哪个操作系统开发的 在 i
  • insertObject:atIndex 的复杂性:

    复杂度是多少 NSArray insertObject atIndex N 或常数 另外 如何找出各种 Objective C 语句的复杂度 有一个在这里讨论 http www cocoadev com index pl NSMutable
  • 桌面上的 AVAudioSession?

    在 mac 桌面上 我试图录制系统声音 以及可选的麦克风声音 但一开始我只是录制系统声音 我正在遵循本指南 https www appcoda com ios avfoundation framework tutorial https ww

随机推荐