2017-06-15 42 views
7

我已經實現了自定義輸入附件視圖,它工作正常,直到iOS 10.3.1。但它在iOS 11 beta中不可見。自定義鍵盤InputAccessoryView在iOS中不可見11

有沒有人遇到過這個問題?

+0

添加更多細節。 – Maddy

+0

我看到同樣的事情。我的輸入配件視圖沒有顯示出來。 –

回答

6

你問的問題沒有太多的細節。但是,對於文本字段使用inputAccessoryView和自定義inputView時,我遇到了同樣的問題。

並通過將自定義inputView的autoresizingMask設置爲.flexibleHeight解決了iOS11上的問題。

yourCustomInputView.autoresizingMask = .flexibleHeight 

希望能夠解決此問題。如果不是可能提供更多信息?

這裏是我添加的輸入配件,櫃面這是更多的幫助(如文本框的擴展名):

public extension UITextField { 

public func addToolbarInputAccessoryView(barButtonItems: [UIBarButtonItem], 
             textColour: UIColor, 
             toolbarHeight: CGFloat = 44, 
             backgroundColour: UIColor = .white) { 

    let toolbar = UIToolbar() 

    toolbar.frame = CGRect(x: 0, y: 0, width: bounds.width, height: toolbarHeight) 
    toolbar.items = barButtonItems 
    toolbar.isTranslucent = false 
    toolbar.barTintColor = backgroundColour 
    toolbar.tintColor = textColour 

    inputAccessoryView = toolbar 
} 

}

,然後在inputView(不是inputAccessoryView),我正在使用日期選擇器 - 只要確保日期選擇器的自動識別掩碼設置爲靈活高度。

+0

我遇到了同樣的問題,並且此解決方案對我無效。另外,我只在iPad上看到這個問題,其他設備都可以,所以看起來很奇怪,不得不在ipad上這樣做。 – user2843570

+0

這個解決方案對我也不適用。我在iPhone上看到這個問題。 – Ruchi

+0

Beta 3解決了這個問題。 – Ruchi

4

Beta 3剛剛問世,有人說它解決了問題,但對我來說卻沒有。

但是我試着將配件視圖設置爲一些愚蠢的東西(100pxls高),並發現iPad上的撤銷/重做/粘貼欄錯誤地坐在我的配件欄頂部。 所以我添加以下代碼,以擺脫蘋果吧(這是毫無意義的我的自定義選擇器反正)和問題走了

希望這有助於有人

- (void)textFieldDidBeginEditing:(UITextField*)textField 
{ 
    UITextInputAssistantItem* item = [textField inputAssistantItem]; 
    item.leadingBarButtonGroups = @[]; 
    item.trailingBarButtonGroups = @[]; 
} 
0

我有同樣的問題而且我發現,消除所有的bottomtopleadingtrainingleft,用於分配accessoryView的 視圖right約束解決了這個問題。

7

PSA:如果您使用UIToolbar作爲您的自定義視圖,它目前在iOS 11 GM中被破解。 而不是如何修復它,只是將其更改爲UIView。 你會失去模糊效果,但它會起作用。

+1

這節省了我很多時間,非常感謝! – LulzCow

0

UIToolBar在iOS 11中被破壞。但是您可以使用UIView作爲inputAccessoryView來完成同樣的事情。示例代碼段在這裏:

CGFloat width = [[UIScreen mainScreen] bounds].size.width; 
UIView* toolBar = [[UIView alloc] initWithFrame:CGRectMake(0.0f,0.0f, width, 44.0f)]; 
toolBar.backgroundColor = [UIColor colorWithRed:0.97f green:0.97f blue:0.97f alpha:1.0f]; 

UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20.0 , 0.0f, width, 44.0f)]; 
[titleLabel setFont:[UIFont fontWithName:@"Helvetica" size:13]]; 
[titleLabel setBackgroundColor:[UIColor clearColor]]; 
[titleLabel setTextColor:[UIColor redColor]]; 
[titleLabel setText:@"Title"]; 
[titleLabel setTextAlignment:NSTextAlignmentLeft]; 
[toolBar addSubview:titleLabel]; 

UIButton *doneBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[doneBtn setTitle:@"Done" forState:UIControlStateNormal]; 
doneBtn.tintColor = [UIColor colorWithRed:(float)179/255 green:(float)27/255 blue:(float)163/255 alpha:1]; 
[doneBtn.titleLabel setFont:[UIFont fontWithName:@"Helvetica" size:16]]; 
[doneBtn addTarget:self action:@selector(btnTxtDoneAction) forControlEvents:UIControlEventTouchUpInside]; 
[doneBtn setFrame:CGRectMake(width-70, 6, 50, 32)]; 
[toolBar addSubview:doneBtn]; 

[toolBar sizeToFit]; 

txtMessageView.inputAccessoryView = toolBar; 

希望這有助於.. :)

3

爲了避免inputAccessoryView問題在iOS的11 UITextFieldUITextView,只需使用下面的代碼:

UIView *inputView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 150)]; 

self.monthPickerView = [[UIPickerView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 150)]; 

    self.monthPickerView.backgroundColor = [UIColor whiteColor]; 

    self.monthPickerView.delegate = self; 

    self.monthPickerView.dataSource = self; 
[inputView addSubview:self.monthPickerView]; 

    cell.monthTextField.inputView = inputView ; 

self.monthTextField.inputAccessoryView = [self doneButtonAccessoryView]; 


// doneButtonAccessoryView Method 


-(UIToolbar*)doneButtonAccessoryView 
{ 

    UIToolbar *kbToolbar = [[UIToolbar alloc] init]; 
    [kbToolbar sizeToFit]; 
    [kbToolbar setBarTintColor:[UIColor whiteColor]]; 
    UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" 
                    style:UIBarButtonItemStyleDone target:self 
                    action:@selector(doneClicked)]; 

    UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" 
                    style:UIBarButtonItemStyleDone target:self 
                    action:@selector(cancelClicked)]; 
    NSDictionary *attrDict; 

    attrDict = [NSDictionary dictionaryWithObjectsAndKeys: 
       [UIFont fontWithName:@"Helvetica-Bold" size:16.0], NSFontAttributeName, nil]; 
[doneButton setTitleTextAttributes:attrDict forState:UIControlStateNormal]; 
    UIBarButtonItem *flexWidth = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace 
                       target:self action:nil]; 

    [kbToolbar setItems:[NSArray arrayWithObjects:cancelButton,flexWidth, doneButton, nil]]; 
    return kbToolbar; 
}