2012-01-03 23 views
6

Tôi không biết bất kỳ Mục tiêu-C nào, đó là lý do tôi sử dụng PhoneGap để tạo ứng dụng iOS. Có một lỗ hổng lớn trong PhoneGap cho iOS. Bàn phím liên tục có trợ lý biểu mẫu (các nút 'tiếp theo', 'trước đó' và 'đã thực hiện'). Có rất ít thông tin trên web về cách loại bỏ điều này, tất cả các câu hỏi về Stackoverflow về nó nói rằng Không thể nào. Nhưng sau một thời gian, tôi tình cờ gặp hướng dẫn này. Đoạn cuối cho bạn biết cách thực hiện. Và nó hoạt động, tôi đã tải xuống và thử nghiệm ứng dụng đã hoàn thành.Làm cách nào để cài đặt tập lệnh này vào PhoneGap cho iOS

Nhưng vì tôi không biết làm thế nào để thực hiện hầu hết mọi thứ trong Xcode, hoặc trong Objective-C, tôi không biết các phần của hai đoạn mã sẽ đi vào đâu, anh ta không nói trong hướng dẫn.

Bất cứ ai có thể cho tôi biết vị trí của tệp ứng dụng PhoneGap trong đó? Tôi đánh giá cao nó ồ ạt, điều này đã làm tôi thất vọng cả ngày.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; 

Và đây

RichTextEditorViewController *viewController = [[RichTextEditorViewController alloc] initWithNibName:@"RichTextEditorViewController" bundle:nil]; 
self.viewController = [[UINavigationController alloc] initWithRootViewController:viewController]; 

Ngoài này

- (void)removeBar { 
    // Locate non-UIWindow. 
    UIWindow *keyboardWindow = nil; 
    for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) { 
     if (![[testWindow class] isEqual:[UIWindow class]]) { 
      keyboardWindow = testWindow; 
      break; 
     } 
    } 

    // Locate UIWebFormView. 
    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) { 
        [subviewWhichIsPossibleFormView removeFromSuperview]; 
       } 
      } 
     } 
    } 
} 

Cảm ơn bạn!

+2

Lời lời khuyên. Tìm hiểu obj-c và bạn sẽ hạnh phúc hơn nhiều. –

Trả lời

16

Tôi đã bắt gặp sự cần thiết phải tự làm điều này. Tôi là một nhà phát triển IOS, nhưng cần phải sử dụng phonegap để giảm chi phí cho nhà phát triển đa nền tảng.

Dù sao, tôi đã sửa mã của bạn. As, tôi đoán, bạn không muốn tốn thời gian của bạn học obj-c, bạn chỉ cần thay thế các nội dung của MainViewController.m của bạn như sau:

#import "MainViewController.h" 

@implementation MainViewController 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; 
    } 
    return self; 
} 

- (void)didReceiveMemoryWarning 
{ 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc that aren't in use. 
} 

#pragma mark - View lifecycle 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 
} 

- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return [super shouldAutorotateToInterfaceOrientation:interfaceOrientation]; 
} 

- (void) removeBar { 
    // Locate non-UIWindow. 
    UIWindow *keyboardWindow = nil; 
    for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) { 
     if (![[testWindow class] isEqual:[UIWindow class]]) { 
      keyboardWindow = testWindow; 
      break; 
     } 
    } 

    // Locate UIWebFormView. 
    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) { 
        [subviewWhichIsPossibleFormView removeFromSuperview]; 
       } 
      } 
     } 
    } 
} 

- (void)keyboardWillShow:(NSNotification*) notification { 
    // remove the bar in the next runloop (not actually created at this point) 
    [self performSelector:@selector(removeBar) withObject:nil afterDelay:0]; 
} 

@end 

như một lời cảnh báo, đây là một chút của một giải pháp hacky (nhưng sau đó là sử dụng phonegap!), và có thể phá vỡ trong các phiên bản tương lai của iOS. Nhưng tôi đoán chúng tôi sửa chữa khi nói đến nó ...

+0

Cảm ơn bạn rất nhiều! –

+0

Dude, cảm ơn ALOT! Tôi ngạc nhiên khi câu trả lời của bạn không được đưa ra thông qua các cuộc hẹn trước đây của tôi. Câu trả lời này chắc chắn xứng đáng là cách nâng cao hơn. – hasen

+0

Sau khi thử điều này, tôi gặp phải một vấn đề nhỏ. Mặc dù điều này không loại bỏ thanh màu đen khỏi màn hình, thanh vẫn là loại "vẫn ở đó", nó ảnh hưởng đến cách cuộn webview. Có nghĩa là, nếu một số trường đầu vào là "đằng sau" thanh đó, thì hệ thống sẽ buộc chế độ xem cuộn lên – hasen

0

Có một số plugin PhoneGap để tăng cường kiểm soát bàn phím. Mặc dù tôi đã không sử dụng này được nêu ra có vẻ như Ionic Keyboard Plugin có thể cung cấp những gì bạn đang cố gắng để làm.

"Ẩn thanh phụ kiện bàn phím bằng các nút tiếp theo, trước đó và đã thực hiện". Phương pháp: cordova.plugins.Keyboard.hideKeyboardAccessoryBar

Để thêm nó: cordova cắm thêm https://github.com/driftyco/ionic-plugins-keyboard.git

Các vấn đề liên quan