简体   繁体   English

在UISplitviewCOntroller中将JSQMessagesViewController用作detailView时,KeyBoardToolBar只需要出现在DetailViewController中

[英]When using JSQMessagesViewController as detailView in UISplitviewCOntroller, KeyBoardToolBar needs to appear in DetailViewController only

When using JSQMessagesViewController as detailView in UISplitViewController, KeyBoardToolBar needs to appear in DetailViewController only 在UISplitViewController中将JSQMessagesViewController用作detailView时,KeyBoardToolBar仅需要出现在DetailViewController中

在此处输入图片说明

late answer... 迟来的答案...

if u want to reduce the inputToolbar you need to create a subclass of JSQMessagesToolbarContentView and provide your own view for the tool bar's content view. 如果要减少inputToolbar ,则需要创建JSQMessagesToolbarContentView的子类,并为工具栏的内容视图提供自己的视图。

below i am giving the sample example, create a subcalss of JSQMessagesToolbarContentView name it as JSQMessagesToolbarContentView_custom in the subcalss add below code, 在下面的示例中,创建一个JSQMessagesToolbarContentView的JSQMessagesToolbarContentView命名为JSQMessagesToolbarContentView_custom ,在下面的代码中添加以下代码,

#import "JSQMessagesToolbarContentView.h"

@interface JSQMessagesToolbarContentView_custom : JSQMessagesToolbarContentView
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *holderViewLeadingConstraint;
@end

and in JSQMessagesToolbarContentView_custom.m file, JSQMessagesToolbarContentView_custom.m文件中,

#import "UIView+JSQMessages.h"
#import "JSQMessagesToolbarContentView_custom.h"

@implementation JSQMessagesToolbarContentView_custom

+ (UINib *)nib
{
      return [UINib nibWithNibName:NSStringFromClass([JSQMessagesToolbarContentView_custom class])
                      bundle:[NSBundle bundleForClass:[JSQMessagesToolbarContentView_custom class]]];
}

#pragma mark - Initialization

- (void)awakeFromNib
{
   [super awakeFromNib];
   [self setTranslatesAutoresizingMaskIntoConstraints:NO];
   self.backgroundColor = [UIColor clearColor];
}

//below method will place the contentview to desired position 
- (void)layoutSubviews
{
   [super layoutSubviews];
   self.holderViewLeadingConstraint.constant = 320;
}

#pragma mark - Setters

- (void)setBackgroundColor:(UIColor *)backgroundColor
{
   [super setBackgroundColor:backgroundColor];
   self.leftBarButtonContainerView.backgroundColor = backgroundColor;
   self.rightBarButtonContainerView.backgroundColor = backgroundColor;
}

- (void)setLeftBarButtonItem:(UIButton *)leftBarButtonItem
{
   [super setLeftBarButtonItem:leftBarButtonItem];  
}

- (void)setLeftBarButtonItemWidth:(CGFloat)leftBarButtonItemWidth
{  
   // self.leftBarButtonContainerViewWidthConstraint.constant = leftBarButtonItemWidth;
   [self setNeedsUpdateConstraints];
}

- (void)setRightBarButtonItem:(UIButton *)rightBarButtonItem
{
   [super setRightBarButtonItem:rightBarButtonItem]; 
}

- (void)setRightBarButtonItemWidth:(CGFloat)rightBarButtonItemWidth
{  
   //  self.rightBarButtonContainerViewWidthConstraint.constant = rightBarButtonItemWidth;
   [self setNeedsUpdateConstraints];
}

- (void)setRightContentPadding:(CGFloat)rightContentPadding
{
   // self.rightHorizontalSpacingConstraint.constant = rightContentPadding;
  [self setNeedsUpdateConstraints];
}

- (void)setLeftContentPadding:(CGFloat)leftContentPadding
{
   //  self.leftHorizontalSpacingConstraint.constant = leftContentPadding;
   [self setNeedsUpdateConstraints];
}

#pragma mark - UIView overrides

- (void)setNeedsDisplay
{
    [super setNeedsDisplay];
    [self.textView setNeedsDisplay];
}


//return the custom view that we are going to create next 
- (JSQMessagesToolbarContentView_custom *)loadToolbarContentView
{
   NSArray *nibViews = [[NSBundle bundleForClass:[JSQMessagesToolbarContentView_custom class]] loadNibNamed:NSStringFromClass([JSQMessagesToolbarContentView_custom class])  owner:nil  options:nil];
  return nibViews.firstObject;
}

after this you need to create add new .xib file name it as JSQMessagesToolbarContentView_custom.xib this file contains our small content view for the inputToolbar and more importantly set the out let connections as doing the demo example and aslo set the view class name to JSQMessagesToolbarContentView_custom . 在此之后,你需要创建新添加.xib文件命名为JSQMessagesToolbarContentView_custom.xib该文件包含我们的小内容视图的inputToolbar更重要的是设置了让连接为做演示的例子和ASLO设置视图类名JSQMessagesToolbarContentView_custom hear i can only add image of the custom view. 听说我只能添加自定义视图的图像。

在此处输入图片说明

now create a outlet for leading constraint to reduce the size of the content view as give below, 现在为领先的约束创建出口,以减小内容视图的大小,如下所示,

在此处输入图片说明

and add the constraints outlet's as given in the demo. 并按照演示中的说明添加约束出口。 so if u add some constrians without modifying the base class it will give error or runtime error so edit the base class also 因此,如果您在不修改基类的情况下添加了一些constrian,它将给出错误或运行时错误,因此也请编辑基类

now go to JSQMessagesToolbarContentView.h and add the blow properties form JSQMessagesToolbarContentView.m just cut and past and make it public. 现在转到JSQMessagesToolbarContentView.h并添加剪切属性表单JSQMessagesToolbarContentView.m ,将其剪切过去并使其公开。

@interface JSQMessagesToolbarContentView : UIView

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *leftBarButtonContainerViewWidthConstraint;


@property (weak, nonatomic) IBOutlet NSLayoutConstraint *rightBarButtonContainerViewWidthConstraint;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *leftHorizontalSpacingConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *rightHorizontalSpacingConstraint;

//...rest of the code 

now in the JSQMessagesInputToolbar.m file, in order to make the tool bar transperent for half of the splitview, 现在在JSQMessagesInputToolbar.m文件中,为了使工具栏在splitview的一半范围内变得透明,

- (void)awakeFromNib
{
    [super awakeFromNib];
     //...rest of the code
    [self setBackgroundImage:[UIImage new]//imageNamed:@"topbar"]
              forToolbarPosition:UIToolbarPositionAny
                      barMetrics:UIBarMetricsDefault];
    [self setShadowImage:[UIImage new] forToolbarPosition:UIBarPositionAny];
    [self setBackgroundColor:[UIColor clearColor]];

}

thats it now run the project, and change the leading constraints constant you see below output, 多数民众赞成现在它运行该项目,并更改输出下面看到的领先约束常量,

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用JSQMessagesViewController时,UI不会出现 - When Using JSQMessagesViewController the UI does not appear 仅在UISplitViewController的DetailViewController中呈现视图控制器 - Presenting a View controller only in the DetailViewController of UISplitViewController 当我在UISplitViewController中将iPad转到纵向模式时,调整detailViewController的pagecontrolview的大小 - Resize the pagecontrolview of detailViewController when i turn iPad to Portrait mode in UISplitViewController UISplitViewController,重用DetailViewController(Swift) - UISplitViewController, reuse DetailViewController (Swift) UISplitViewController与tableView作为detailView错误 - UISplitViewController with tableView as detailView bug UISplitViewController:在detailView中导航 - UISplitViewController: Navigating within detailView 更新UISplitViewController子类中的DetailViewController框架 - Update frame of DetailViewController in subclass of UISplitViewController 为什么当我在JSQMessagesViewController中按下发送按钮时出现2条消息 - Why do 2 messages appear when I press the send button in JSQMessagesViewController UITableView,uisplitviewcontroller-一种管理detailview的方法? - UITableView, uisplitviewcontroller - a way to manage detailview? 为什么detailViewController不在UISplitViewController.viewControllers中? - Why detailViewController is not in UISplitViewController.viewControllers anymore?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM