禁用MFMailComposeViewController上的编辑 [英] Disable editing on MFMailComposeViewController

查看:74
本文介绍了禁用MFMailComposeViewController上的编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个业务规则,我们需要限制MFMailComposeViewController上电子邮件正文内容的编辑。内容将预先填充,并且需要保持静态。是否可以获取UITextView对象并将其设置为禁用或沿着这些行?

We have a business rule where we need to restrict the editing of the email body content on MFMailComposeViewController. The content will be pre-populated and needs to remain static. Is it possible to grab the UITextView object and set it to disabled or something along those lines?

另一个想法是在UITextView的顶部显示清晰的视图以防止任何交互。

Another thought was to display a clear view over the top of the UITextView to prevent any interaction.

任何想法?

推荐答案

好的,是的,答案是不可能不使用私有API

Ok, so yes, the answer is that it is impossible without using private APIs.

我设法用以下代码完成。

I managed to do it with the following code.

- (void) getMFComposeBodyFieldViewFromView:(UIView *)view {
   for (UIView *item in view.subviews) {
    if ([[[item class] description] isEqualToString:@"MFComposeTextContentView"]) {
         self.mailBodyView = item;
         break;
      }
      if([item.subviews count] > 0) {
        [self getMFComposeBodyFieldViewFromView:item];
      }
   }
}

然后调用上面的方法它设置了ivar mailBodyView ,然后在 UIWebDocumentView _setEditable:方法c $ c>哪个 MFComposeBodyField 继承自。

Then call the above method so that it sets the ivar mailBodyView and then call the _setEditable: method on UIWebDocumentView which MFComposeBodyField inherits from.

[self getMFComposeBodyFieldViewFromView:mailComposeViewController.view];
[self.mailBodyView setEditable:NO];

这会导致正文中的内容无法编辑,因为键盘依旧,这种交互很有点时髦出现,你仍然可以移动光标并选择一些东西,但它肯定会阻止用户编辑。

This causes the content in the body to be uneditable, the interaction is kind of funky because the keyboard still appears and you can still move the cursor around and select things but it definitely prevents the user from editing.

更新

我更新了代码以查找 MFComposeTextContentView 这是 MFComposeBodyField 的父级,我在该对象上调用 setEditable:防止键盘出现,更好的解决方案!

I updated the code to look for MFComposeTextContentView which is the parent of MFComposeBodyField and I call setEditable: on that object which prevents the keyboard from coming up, much better solution!

这篇关于禁用MFMailComposeViewController上的编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆