【问题标题】:iOS: [imagePickerController.cameraOverlayView addSubview:] not workingiOS:[imagePickerController.cameraOverlayView addSubview:] 不工作
【发布时间】:2012-10-12 20:13:59
【问题描述】:

我正在尝试将 UIToolbar 添加到我的 cameraOverlayView 以用于自定义 imagePickerController。这是我要使用的代码:

[self.imagePickerController.cameraOverlayView addSubview:self.topToolbar];

尝试添加 UIToolbar 时,没有任何显示。如果我使用,将其封装到 UIView 并将其设置为 view 属性是可行的:

[self.imagePickerController.cameraOverlayView addSubview:self.view];

但是当我想添加多个视图时,这限制了我只能使用一个视图进行叠加。我知道我可以将所有内容封装到一个大视图中,但是当我这样做时,我的底部工具栏无法正确显示。

有没有人成功地将 UIToolbar 作为子视图添加到 cameraOverlayView 中?

【问题讨论】:

  • [self.imagePickerController.cameraOverlayView addSubview:self.topToolbar];对我来说很好。我认为我们需要更多细节。你是如何初始化你的工具栏的?

标签: iphone ios ios5 ios4 uiimagepickercontroller


【解决方案1】:

我认为你需要一个视图来将你需要的所有东西放在你的 cameraOverlay 中。 例如:

TempView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; TempView.alpha = 1.0;

anImageView1 = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@""]];
anImageView1.frame = CGRectMake(0, 0, anImageView1.image.size.width, anImageView1.image.size.height-50);
anImageView1.hidden = NO;
anImageView1.alpha = 1.0f;

tabBarHolder = [[UIImageView alloc]init];
tabBarHolder.backgroundColor = [UIColor blackColor];
tabBarHolder.frame = CGRectMake(0, 415, 320, 80);

tampBtn = [[UIButton alloc] initWithFrame:CGRectMake(15, 430, 35, 35)];
[tampBtn setBackgroundImage:[UIImage imageNamed:@"iconBack.png"] forState:UIControlStateNormal];
[tampBtn addTarget:self 
            action:@selector(xup) 
  forControlEvents:UIControlEventTouchUpInside];

ctampBtn = [[UIButton alloc] initWithFrame:CGRectMake(145, 430, 35, 35)];
[ctampBtn setBackgroundImage:[UIImage imageNamed:@"iconCamera.png"] forState:UIControlStateNormal];
[ctampBtn addTarget:self 
             action:@selector(takephoto) 
   forControlEvents:UIControlEventTouchUpInside];

[TempView addSubview:ctampBtn];
[TempView addSubview:tampBtn];
[TempView addSubview:anImageView1];
[TempView addSubview:tabBarHolder];
[TempView bringSubviewToFront:tabBarHolder];
[TempView bringSubviewToFront: ctampBtn];
[TempView bringSubviewToFront:tampBtn];

imagePicker.cameraOverlayView =TempView;

【讨论】:

  • 对,但是比如说我只想要一个工具栏。 UIToolbar 是 UIView 的子类。不应该单独添加工具栏吗?
猜你喜欢
  • 2020-03-21
  • 1970-01-01
  • 1970-01-01
  • 2013-03-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多