OGeek|极客世界-中国程序员成长平台

标题: iphone - 将 UITextField 添加到 cameraOverlay [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 08:48
标题: iphone - 将 UITextField 添加到 cameraOverlay

大家好,我正在尝试向我的 cameraOverlay 添加一个 UITextField。我让它显示在我的相机 View 上,但它不可编辑。它根本没有反应。我需要采取什么方法让它得到响应?

我看过这个问题,但不明白如何在我的 cameraOverly 上设置一个透明的 View Controller。

Suggestion for camera overlay

提前致谢!



Best Answer-推荐答案


步骤应该是:

  1. 创建您的选择器。

  2. 创建一个带有 clearColor 背景的空 View 。

  3. 使用 addSubview: 将您的文本字段添加到第 2 步中的 View 中。

  4. 将 cameraOverlayView 设置为步骤 2 中创建的 View 。

  5. 出示您的选择器。

在代码中:

//self.picker and self.textField being your UIImagePickerController and UITextField instances.
emptyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; //This frame will make it fullscreen...
emptyView.backgroundColor = [UIColor clearColor];
[emptyView setAlpha:1.0]; //I think it is not necessary,  but it wont hurt to add this line.
self.textField.frame = CGRectMake(100, 100, self.textField.frame.size.width, self.textField.frame.size.height); //Here you can specify the position in this case 100x 100y of your textField preserving the width and height.
[emptyView addSubview:self.textField];
self.picker.cameraOverlayView = emptyView; //Which by the way is not empty any more..
[emptyView release];
[self presentModalViewController:self.picker animated:YES];
[self.picker release];

我自己在这里输入了代码,所以它可能有一些错字,希望它有帮助!

关于iphone - 将 UITextField 添加到 cameraOverlay,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7053858/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4