UISplitViewController detail-only inputAccessoryView
Asked Answered
O

2

7

I am trying to imitate Apple's iMessage application in terms of the message input toolbar. Apple has a UIToolbar which is the input accessory view of a UITextView it contains, and also the inputAccessoryView of the actual view. That way, the toolbar is always present, and when the keyboard appears, it slides with the keyboard.

On the iPad, they seem to have a UISplitViewController, and the toolbar is part of the detail view controller. Now, when I have the same set up, my detail view's input accessory toolbar stretches to the whole width, so just like the keyboard, it also overlaps the master view controller. Apple, on the other hand, somehow managed to restrict the input accessory to the constraints of the detail view.

How can I do that?

Octavus answered 11/7, 2014 at 12:7 Comment(4)
I have solved this in a different way, similar to how Apple has implemented it in their own Messages app. If anyone is interested, I can post my solution.Corvese
@LeoNatan I am more than interested. I am DYING to know how Apple has implemented it. Please do post your solution!Octavus
Saw this comment just now. Will do tomorrow at work, when I am near my code.Corvese
@LéoNatan also interested, if you still have the codeOrgulous
S
3

That's not possible to have inputAccessoryView only for one viewController in UISplitViewController. My way to do it is to have inputAccessoryView as container and have subview in it with 320px offset.


 - (void)setFrame:(CGRect)frame
{
    if (RUNNING_ON_IPAD)
    {
        CGFloat superviewWidth = self.superview.bounds.size.width;

        CGFloat offset = 321.f;
        frame.origin.x = offset;
        frame.size.width = superviewWidth - offset;
    }

    [super setFrame:frame];

}
Salvidor answered 29/7, 2014 at 10:45 Comment(1)
Hey, sorry, I did not see your mail. May I ask which address you used?Octavus
G
0

Instead of using an inputAccessoryView, just add your accessoryView as a subview at the bottom of the appropriate view. Then synchronize movement with the keyboard as explained here: Synchronizing Animations in keyboardWillShow keyboardWillHide -- Hardware Keyboard & Virtual Keyboard Simultaneously

Gasholder answered 27/1, 2017 at 20:1 Comment(2)
That won't work when moving an undocked keyboard on an iPad, because the events will only fire once the keyboard movement is completed.Octavus
Good point. Maybe best option is to create 2 identical accessory views, one as subview to activate the keyboard, and a second that is assigned as an inputAccessoryView for when the keyboard is visible. Or, possibly, a single view can alternate playing those roles, though I could not get that to work.Gasholder

© 2022 - 2024 — McMap. All rights reserved.