键盘操作就像在iOS中7消息应用程序 [英] Keyboard handling just like in Messages app in iOS 7

查看:189
本文介绍了键盘操作就像在iOS中7消息应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现一种观点认为是类似于在消息应用程序中发生什么某种方式,所以附着在屏幕底部与UITextView的一个图,也有的UITableView表示的主要内容。当它被窃听它与键盘向上滑动并且当键盘被驳回它滑动返回到屏幕的底部。

这部分,我已经和它的工作完美 - 我只是订阅键盘的通知 - 将隐藏和显示WIL

问题是,我已经设置键盘解雇模式的UITableView互动,我不能捕获变更键盘的时候它被平移。

的第二个问题是,这条带的UITextView涵盖的UITableView的某些部分。如何解决这一问题?我仍然希望的UITableView是这样的吧下的就像在邮件应用程序。

我在所有地方使用自动版式。

任何帮助将AP preciated!

============

EDIT1:
下面是一些code:

查看层次结构如下:

查看
   - UITableView的(这其中将包含信息​​)
   - UIView的(这个会滑动)

UITableView的是有约束的顶部,左,右和父视图的底部,使其充满整个屏幕。
UIView的有约束左,右和父视图的底部,所以它被粘在底部 - 我通过约束不断调整其移动

在viewWillAppear中的方法:

  NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.DidShowNotification,OnKeyboardDidShowNotification);
        NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.WillChangeFrameNotification,OnKeyboardDidShowNotification);
        NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.WillHideNotification,OnKeyboardWillHideNotification);

和这里的方法:

 无效OnKeyboardDidShowNotification(NSNotification通知)
    {
        AdjustViewToKeyboard(Ui.KeyboardHeightFromNotification(通知),通知);
    }    无效OnKeyboardWillHideNotification(NSNotification通知)
    {
        AdjustViewToKeyboard(0.0,通知);
    }    无效AdjustViewToKeyboard(浮点偏移,NSNotification通知= NULL)
    {
        commentEditViewBottomConstraint.Constant = -offset;        如果(通知!= NULL){
            UIView.BeginAnimations(NULL,IntPtr.Zero);
            UIView.SetAnimationDuration(Ui.KeyboardAnimationDurationFromNotification(通知));
            UIView.SetAnimationCurve((UIViewAnimationCurve)Ui.KeyboardAnimationCurveFromNotification(通知));
            UIView.SetAnimationBeginsFromCurrentState(真);
        }        View.LayoutIfNeeded();
        commentEditView.LayoutIfNeeded();        VAR插图= commentsListView.ContentInset;
        insets.Bottom =偏移;
        commentsListView.ContentInset =插图;        如果(通知!= NULL){
            UIView.CommitAnimations();
        }
    }


解决方案

我做了一个开源的lib出于这样的目的。它适用于iOS 7和8,并设置为cocoapod工作为好。

https://github.com/oseparovic/MessageComposerView

下面是什么它看起来像一个示例:

您可以使用一个很基本的的init 功能如下所示与屏幕宽度和高度的默认例如创建它。

  self.messageComposerView = [[MessageComposerView的alloc]初始化];
self.messageComposerView.delegate =自我;
[self.view addSubview:self.messageComposerView];

有一些其他的初始化是也可让你自定义边框,键盘偏移和TextView的最大高度,以及一些代表挂接到框架的变化和按钮点击。见自述更多!

I am implementing a view that is in some way similar to what happens in Messages app, so there is a view with UITextView attached to the bottom of the screen and there is also UITableView showing the main content. When it is tapped it slides up with the keyboard and when keyboard is dismissed it slides back to the bottom of the screen.

That part I have and it is working perfectly - I just subscribed to keyboard notifications - will hide and wil show.

The problem is that I have set keyboard dismiss mode on UITableView to interactive and I cannot capture changes to keyboard when it is panning.

The second problem is that this bar with uitextview is covering some part of uitableview. How to fix this? I still want the uitableview to be "under" this bar just like in messages app.

I am using AutoLayout in all places.

Any help will be appreciated!

============

EDIT1: Here is some code:

View Hierarchy is as follows:

View - UITableView (this one will contain "messages") - UIView (this one will slide)

UITableView is has constraints to top, left, right and bottom of parent view so it fills whole screen. UIView has constraints to left, right and bottom of parent view so it is glued to the bottom - I moved it by adjusting constant on constraint.

In ViewWillAppear method:

        NSNotificationCenter.DefaultCenter.AddObserver (UIKeyboard.DidShowNotification, OnKeyboardDidShowNotification);
        NSNotificationCenter.DefaultCenter.AddObserver (UIKeyboard.WillChangeFrameNotification, OnKeyboardDidShowNotification);
        NSNotificationCenter.DefaultCenter.AddObserver (UIKeyboard.WillHideNotification, OnKeyboardWillHideNotification);

And here are methods:

    void OnKeyboardDidShowNotification (NSNotification notification)
    {
        AdjustViewToKeyboard (Ui.KeyboardHeightFromNotification (notification), notification);
    }

    void OnKeyboardWillHideNotification (NSNotification notification)
    {   
        AdjustViewToKeyboard (0.0f, notification);
    }

    void AdjustViewToKeyboard (float offset, NSNotification notification = null)
    {
        commentEditViewBottomConstraint.Constant = -offset;

        if (notification != null) {
            UIView.BeginAnimations (null, IntPtr.Zero);
            UIView.SetAnimationDuration (Ui.KeyboardAnimationDurationFromNotification (notification));
            UIView.SetAnimationCurve ((UIViewAnimationCurve)Ui.KeyboardAnimationCurveFromNotification (notification));
            UIView.SetAnimationBeginsFromCurrentState (true);
        }

        View.LayoutIfNeeded ();
        commentEditView.LayoutIfNeeded ();

        var insets = commentsListView.ContentInset;
        insets.Bottom = offset;
        commentsListView.ContentInset = insets;

        if (notification != null) {
            UIView.CommitAnimations ();
        }
    }

解决方案

I made an open source lib for exactly this purpose. It works on iOS 7 and 8 and is set up to work as a cocoapod as well.

https://github.com/oseparovic/MessageComposerView

Here's a sample of what it looks like:

You can use a very basic init function as shown below to create it with screen width and default height e.g.:

self.messageComposerView = [[MessageComposerView alloc] init];
self.messageComposerView.delegate = self;
[self.view addSubview:self.messageComposerView];

There are several other initializers that are also available to allow you to customize the frame, keyboard offset and textview max height as well as some delegates to hook into frame changes and button clicks. See readme for more!

这篇关于键盘操作就像在iOS中7消息应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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