Отключить клавиатуру контроллера просмотра почты iPhone с клавишей возврата - PullRequest
1 голос
/ 05 февраля 2010

Как убрать клавиатуру в MFMailComposeViewController, когда пользователь нажимает клавишу возврата?

Ответы [ 2 ]

0 голосов
/ 05 февраля 2010

Я полагаю, что следующее решение, которое я только что разработал, не изменяет и не нарушает надежного взаимодействия с пользователем в контроллере почтового представления - оно просто расширяет его для тех, кто хочет отключить клавиатуру. Я не изменяю функциональность существующих элементов, я только добавляю новый элемент. Часть кода, которая получает высоту клавиатуры после ее отображения, взята из этого ответа . Здесь идет:

- (IBAction)showMailController {
    //Present mail controller on press of a button, set up notification of keyboard showing and hiding
    [nc addObserver:self selector:@selector(keyboardWillShow:) name: UIKeyboardWillShowNotification object:nil];
    [nc addObserver:self selector:@selector(keyboardWillHide:) name: UIKeyboardWillHideNotification object:nil];
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];           
    //... and so on
}        
- (void)keyboardWillShow:(NSNotification *)note {
    //Get view that's controlling the keyboard
    UIWindow* keyWindow = [[UIApplication sharedApplication] keyWindow];
    UIView* firstResponder = [keyWindow performSelector:@selector(firstResponder)];

    //set up dimensions of  dismiss keyboard button and animate it into view, parameters are based on landscape orientation, the keyboard's dimensions and this button's specific dimensions
    CGRect t;
    [[note.userInfo valueForKey:UIKeyboardBoundsUserInfoKey] getValue: &t];
    button.frame = CGRectMake(324,(290-t.size.height),156,37);
    button.alpha = 0.0;
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1.0];    
    [[[[[firstResponder superview] superview] superview] superview] addSubview:button];
    button.alpha = 1.0;
    button.frame = CGRectMake(324,(253-t.size.height),156,37);
    [UIView commitAnimations];
}

- (IBAction)dismissKeyboardInMailView {
    //this is what gets called when the dismiss keyboard button is pressed
    UIWindow* keyWindow = [[UIApplication sharedApplication] keyWindow];
    UIView* firstResponder = [keyWindow performSelector:@selector(firstResponder)];
    [firstResponder resignFirstResponder];
}

- (void)keyboardWillHide:(NSNotification *)note {
    //hide button here
    [button removeFromSuperview];
}
0 голосов
/ 05 февраля 2010

Нет способа изменить поведение MFMailComposeViewController (редактировать: под этим я подразумеваю использование только общедоступных API-интерфейсов таким образом, чтобы Apple не отклоняла ваше приложение - вполне вероятно, что есть способ сделайте это «незаконно», если вы создаете собственное приложение).

http://developer.apple.com/iphone/library/documentation/MessageUI/Reference/MFMailComposeViewController_class/Reference/Reference.html

Цитата: "Важно: сам интерфейс составления почты не настраивается и не должен изменяться вашим приложением."

Это соответствует HIG от Apple, чтобы всегда обеспечивать единообразное, последовательное поведение для отправки почты.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...