Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.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
Ios UIImagePickerController、自定义UIButton和自动布局_Ios_Objective C_Uibutton_Autolayout_Uiimagepickercontroller - Fatal编程技术网

Ios UIImagePickerController、自定义UIButton和自动布局

Ios UIImagePickerController、自定义UIButton和自动布局,ios,objective-c,uibutton,autolayout,uiimagepickercontroller,Ios,Objective C,Uibutton,Autolayout,Uiimagepickercontroller,我试图使用自动布局约束将自定义按钮放入UIImagePickerController - (void)createTimerButtonFor:(UIImagePickerController*)picker { UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setTitle:@"Timer" forState:UIControlStateNormal]; NSLayoutConstraint*

我试图使用自动布局约束将自定义按钮放入UIImagePickerController

- (void)createTimerButtonFor:(UIImagePickerController*)picker
{
UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setTitle:@"Timer" forState:UIControlStateNormal];
NSLayoutConstraint* constraint1 = [NSLayoutConstraint constraintWithItem:picker.view attribute:NSLayoutAttributeCenterX relatedBy: NSLayoutRelationEqual toItem:button attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];

NSLayoutConstraint* constraint2 = [NSLayoutConstraint constraintWithItem:picker.view attribute:NSLayoutAttributeTop relatedBy: NSLayoutRelationEqual toItem:button attribute:NSLayoutAttributeTop multiplier:1 constant:0];

NSLayoutConstraint *heightConstraint =
[NSLayoutConstraint constraintWithItem:button
                             attribute:NSLayoutAttributeHeight
                             relatedBy:NSLayoutRelationEqual
                                toItem:nil
                             attribute:NSLayoutAttributeNotAnAttribute
                            multiplier:1.0
                              constant:100.0];
NSLayoutConstraint *widthConstraint =
[NSLayoutConstraint constraintWithItem:button
                             attribute:NSLayoutAttributeWidth
                             relatedBy:NSLayoutRelationEqual
                                toItem:nil
                             attribute:NSLayoutAttributeNotAnAttribute
                            multiplier:1.0
                              constant:100.0];


[picker.view addSubview:button];

[picker.view addConstraint:constraint1];
[picker.view addConstraint:constraint2];
[button addConstraint:heightConstraint];
[button addConstraint:widthConstraint];
}

甚至有可能这样做吗?我做错什么了吗?

Dzior,我认为将按钮添加到选择器视图并让autolayout为您定位是相当困难的。我想可能它没有完全使用自动布局

我曾尝试禁用它旋转,但iOS 8之前的所有技巧在iOS 8上都无法正常工作


创建覆盖视图并将按钮放在覆盖视图中会更容易,因为您可以完全控制覆盖视图类。

您能解释一下按钮的确切位置吗?它以什么方式不起作用(例如“按钮未显示”或“按钮不在正确的位置”)?此外,在应用引用约束的约束之前,约束中涉及的视图必须位于视图层次中。您应该得到一个异常或至少一个日志输出。