Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 在UIToolbar内向上移动UIBarButtonims_Iphone_Objective C_Uibarbuttonitem_Uitoolbar - Fatal编程技术网

Iphone 在UIToolbar内向上移动UIBarButtonims

Iphone 在UIToolbar内向上移动UIBarButtonims,iphone,objective-c,uibarbuttonitem,uitoolbar,Iphone,Objective C,Uibarbuttonitem,Uitoolbar,我创建了一个自定义的UIToolbar实例来使用背景图像,对于我的特定图像,实际工具栏的高度比图像本身要小(例如,工具栏是60px,较低的20px是透明的,侧面有一个小项目)。这在一定程度上混淆了UIToolbar,因为所有UIBarButtonim都必须垂直居中,这与我的图像不一致 我可以设置一个边距或什么东西使按钮向上滑动吗?我考虑过UIButtons,但我需要一个图像来匹配现有工具栏的外观,因此我更喜欢动态生成按钮。我不完全确定,但这可能会起作用:-(void)setBackgroundV

我创建了一个自定义的UIToolbar实例来使用背景图像,对于我的特定图像,实际工具栏的高度比图像本身要小(例如,工具栏是60px,较低的20px是透明的,侧面有一个小项目)。这在一定程度上混淆了UIToolbar,因为所有UIBarButtonim都必须垂直居中,这与我的图像不一致


我可以设置一个边距或什么东西使按钮向上滑动吗?我考虑过UIButtons,但我需要一个图像来匹配现有工具栏的外观,因此我更喜欢动态生成按钮。

我不完全确定,但这可能会起作用:
-(void)setBackgroundVerticalPositionAdjustment:(CGFloat)adjustment for BarMetrics:(UIBarMetrics)barMetrics
用于
UIBarButtonItem


参考资料:

我不完全确定,但这可能会起作用:
-(void)setbackground垂直位置调整:(CGFloat)barMetrics的调整:(UIBarMetrics)barMetrics
用于
uibarbuttoneim


参考资料:

对于最新的iOS版本,我唯一能使其可靠工作的方法是调整
UIToolbar
的内容视图。在我的
UIToolbar
子类中,我在
layoutsubview
中有以下代码:

if ( _preferredHeight )
{
    [self.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull v, NSUInteger idx, BOOL * _Nonnull stop) {

        NSString* className = NSStringFromClass(v.class);
        if ( [className localizedCaseInsensitiveContainsString:@"content"] )
        {
            v.frame = CGRectOffset( self.bounds, 0, 2 * (44 - self->_preferredHeight) );
            *stop = YES;
        }

    }];
}

请注意,这会在
UIToolbar
私有子视图层次结构中四处窥视,在未来的iOS版本中可能不会对AppStore安全或中断。

对于最新的iOS版本,我唯一能使这一功能可靠工作的方法是调整
UIToolbar
的内容视图。在我的
UIToolbar
子类中,我在
layoutsubview
中有以下代码:

if ( _preferredHeight )
{
    [self.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull v, NSUInteger idx, BOOL * _Nonnull stop) {

        NSString* className = NSStringFromClass(v.class);
        if ( [className localizedCaseInsensitiveContainsString:@"content"] )
        {
            v.frame = CGRectOffset( self.bounds, 0, 2 * (44 - self->_preferredHeight) );
            *stop = YES;
        }

    }];
}
请注意,这会在
UIToolbar
私有子视图层次结构中四处窥视,在未来的iOS版本中可能不会对应用商店安全或中断。