gpt4 book ai didi

ios - 以编程方式添加以查看时,UISlider 使应用程序崩溃

转载 作者:行者123 更新时间:2023-11-28 18:23:13 25 4
gpt4 key购买 nike

我有一个自定义的相机覆盖层,它是我有 UISlider 的覆盖层:

@implementation LWOverlayView

- (id)initWithFrame:(CGRect)frame imagePath:(NSString*) imagepath{
if ((self = [super initWithFrame:frame])) {
// Clear the background of the overlay:
self.opaque = NO;
self.backgroundColor = [UIColor clearColor];


UIImageView *overlayGraphicView = [[UIImageView alloc] init];
overlayGraphicView.contentMode = UIViewContentModeScaleAspectFill;
[overlayGraphicView setImageWithURL:[NSURL URLWithString:imagepath]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]];


overlayGraphicView.frame = CGRectMake(80, 140, 160, 120);
[self addSubview:overlayGraphicView];

UIToolbar *toolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 436, 320, 44)];
[toolbar setBarStyle:UIBarStyleBlackOpaque];

UIBarButtonItem *doneButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismiss)];

CGRect frame = CGRectMake(0.0, 0.0, 200.0, 10.0);
UISlider *slider = [[UISlider alloc] initWithFrame:frame];
[slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
[slider setBackgroundColor:[UIColor clearColor]];
slider.minimumValue = 0.0;
slider.maximumValue = 50.0;
slider.continuous = YES;
slider.value = 25.0;


[toolbar setItems:[NSArray arrayWithObjects:doneButton, slider, nil]];

[self addSubview:toolbar];

}
return self;
}

应用崩溃:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UISlider view]: unrecognized selector sent to instance 0x20854fe0'

有什么提示吗?

最佳答案

正如已经指出的那样,您不能直接将 UISlider(或任何其他 UIView)直接添加到工具栏项目列表。

您需要做的是创建一个包含 slider 的 UIBarButtonItem

UIBarButtonItem *sliderBtn = [[UIBarButtonItem alloc] initWithCustonView:slider];

现在将 sliderBtn 添加到数组而不是 slider

您可能会发现需要在 sliderBtn 上设置 width 属性。

关于ios - 以编程方式添加以查看时,UISlider 使应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16611452/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com