2010-02-04 96 views

回答

0

我相信我剛剛開發的以下解決方案不會修改或損壞郵件視圖控制器中的可靠用戶體驗 - 它僅僅爲那些想要關閉鍵盤的用戶提供了可靠性。我不改變現有元素的功能,我只添加一個新元素。在顯示鍵盤後獲得鍵盤高度的代碼部分來自this answer。這裏有:

- (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

沒有辦法改變MFMailComposeViewController的行爲(編輯:由於我的意思是隻使用公共API,這樣你的應用程序不會被Apple拒絕 - 這很可能是一種方法這個「非法」,如果你正在構建一個內部應用程序)。

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

名言:「重要提示:郵件撰寫界面本身不是定製的,不得通過您的應用程序進行修改。」

它符合Apple的HIG始終爲發送郵件提供單一一致的行爲。

+0

我同意默認元素的一致應用很重要。我不相信在混音中添加一個新按鈕會違反這個規定。 – 2010-02-05 02:15:50