[英]When using JSQMessagesViewController as detailView in UISplitviewCOntroller, KeyBoardToolBar needs to appear in DetailViewController only
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.