Cocoa touch 将自定义UIButton添加到UIKeyboard';UIWebView的s附件视图
我需要将摄像头按钮添加到Cocoa touch 将自定义UIButton添加到UIKeyboard';UIWebView的s附件视图,cocoa-touch,uikeyboard,Cocoa Touch,Uikeyboard,我需要将摄像头按钮添加到UIWebView的键盘附件视图工具栏(已经有“上一步”和“下一步”按钮的工具栏) 有没有一个简单的方法可以做到这一点?我仍在寻找更好的方法,但目前有一个解决方案是破坏酒吧,然后像这样重新创建: - (void)viewDidLoad { [super viewDidLoad]; UIWebView *web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; NSURL
UIWebView
的键盘附件视图工具栏(已经有“上一步”和“下一步”按钮的工具栏)
有没有一个简单的方法可以做到这一点?我仍在寻找更好的方法,但目前有一个解决方案是破坏酒吧,然后像这样重新创建:
- (void)viewDidLoad
{
[super viewDidLoad];
UIWebView *web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
NSURL *aURL = [NSURL URLWithString:@"http://www.google.com"];
NSURLRequest *aRequest = [NSURLRequest requestWithURL:aURL];
[web loadRequest:aRequest];
[self.view addSubview:web];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
}
- (void)keyboardWillShow:(NSNotification *)notification {
[self performSelector:@selector(removeBar) withObject:nil afterDelay:0];
}
- (void)removeBar {
UIWindow *keyboardWindow = nil;
for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
if (![[testWindow class] isEqual:[UIWindow class]]) {
keyboardWindow = testWindow;
break;
}
}
for (UIView *possibleFormView in [keyboardWindow subviews]) {
// iOS 5 sticks the UIWebFormView inside a UIPeripheralHostView.
if ([[possibleFormView description] rangeOfString:@"UIPeripheralHostView"].location != NSNotFound) {
for (UIView *subviewWhichIsPossibleFormView in [possibleFormView subviews]) {
if ([[subviewWhichIsPossibleFormView description] rangeOfString:@"UIWebFormAccessory"].location != NSNotFound) {
UISegmentedControl *nav = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Previous",@"Next", nil]];
nav.momentary = YES;
nav.frame = CGRectMake(5, 8, 120, 30);
nav.segmentedControlStyle = UISegmentedControlStyleBar;
nav.tintColor = [UIColor colorWithWhite:0.25 alpha:1];
[nav addTarget:self action:@selector(navigate) forControlEvents:UIControlEventValueChanged];
UIBarButtonItem *pictureBtn =[[UIBarButtonItem alloc] initWithTitle:@"Picture" style:UIBarButtonItemStyleBordered target:self action:@selector(takePic:)];
UIBarButtonItem *flexButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
UIBarButtonItem *doneButton =[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(resignKeyboard)];
NSArray *buttons = [NSArray arrayWithObjects:flexButton,pictureBtn,flexButton,doneButton, nil];
[(UIToolbar *)subviewWhichIsPossibleFormView addSubview:nav];
[(UIToolbar *)subviewWhichIsPossibleFormView setItems:buttons];
}
}
}
}
}
但是,您必须再次实现上一个、下一个和完成的函数。但这不是最难的部分。有一种更简单的方法 将键盘通知保存在
viewDidLoad
之后,您只需要以下方法:
-(void)keyboardDidShow:(NSNotification*)notif
{
NSArray *array = [[UIApplication sharedApplication] windows];
for (UIWindow* wind in array) {
for (UIView* currView in wind.subviews) {
if ([[currView description] hasPrefix:@"<UIPeripheralHostView"]) {
for (UIView* perView in currView.subviews) {
if ([[perView description] hasPrefix:@"<UIWebFormAccessory"]) {
UIBarButtonItem *doneBttn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(resignKeyBoard)];
NSMutableArray *arr = [[NSMutableArray alloc] initWithArray: [(UIToolbar *) perView items]];
[arr addObject:doneBttn];
[(UIToolbar *) perView setItems:arr];
}
}
}
}
}
}
-(无效)键盘显示:(NSNotification*)notif
{
NSArray*数组=[[UIApplication sharedApplication]windows];
用于(UIWindow*阵列中的风){
用于(UIView*风中的currView.子视图){
if([[currView description]hasPrefix:@“我已经看过这两个示例,它们只是显示为创建一个新的辅助视图。我想使用默认视图,该视图显示为uiwebview,但只添加一个按钮。一个允许用户使用相机扫描条形码的相机按钮。如何将该按钮添加到现有设置中?