- 浏览: 2527623 次
- 性别:
- 来自: 苏州
文章分类
最新评论
-
jsntghf:
peio 写道这个怎么运行?Ruby On Rails的环境搭 ...
多文件上传之uploadify -
peio:
这个怎么运行?
多文件上传之uploadify -
往事如烟1:
我的项目是自己init了一个原始的project,之后将ver ...
React Native热部署之CodePush -
jsntghf:
往事如烟1 写道我按照你的说明进行,发现app退出之后,在进入 ...
React Native热部署之CodePush -
往事如烟1:
我按照你的说明进行,发现app退出之后,在进入不正确,请问是什 ...
React Native热部署之CodePush
主要是用到了cameraOverlayView这个属性,我们只要自定义一个UIView即可,这大大简化了我们的工作,核心代码如下所示,其他的请参考附件。
OverlayViewController.h
#import <UIKit/UIKit.h> #import <AudioToolbox/AudioServices.h> @protocol OverlayViewControllerDelegate; @interface OverlayViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate> { id <OverlayViewControllerDelegate> delegate; } @property (nonatomic, assign) id <OverlayViewControllerDelegate> delegate; @property (nonatomic, retain) UIImagePickerController *imagePickerController; - (void)setupImagePicker:(UIImagePickerControllerSourceType)sourceType; @end @protocol OverlayViewControllerDelegate - (void)didTakePicture:(UIImage *)picture; - (void)didFinishWithCamera; @end
OverlayViewController.m
#import "OverlayViewController.h" enum { kOneShot, kRepeatingShot }; @interface OverlayViewController ( ) @property (assign) SystemSoundID tickSound; @property (nonatomic, retain) IBOutlet UIBarButtonItem *takePictureButton; @property (nonatomic, retain) IBOutlet UIBarButtonItem *startStopButton; @property (nonatomic, retain) IBOutlet UIBarButtonItem *timedButton; @property (nonatomic, retain) IBOutlet UIBarButtonItem *cancelButton; @property (nonatomic, retain) NSTimer *tickTimer; @property (nonatomic, retain) NSTimer *cameraTimer; - (IBAction)done:(id)sender; - (IBAction)takePhoto:(id)sender; - (IBAction)startStop:(id)sender; - (IBAction)timedTakePhoto:(id)sender; @end @implementation OverlayViewController @synthesize delegate; #pragma mark - #pragma mark OverlayViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource:@"tick" ofType:@"aiff"]], &_tickSound); self.imagePickerController = [[[UIImagePickerController alloc] init] autorelease]; self.imagePickerController.delegate = self; } return self; } - (void)viewDidUnload { self.takePictureButton = nil; self.startStopButton = nil; self.timedButton = nil; self.cancelButton = nil; self.cameraTimer = nil; [super viewDidUnload]; } - (void)dealloc { [_takePictureButton release]; [_startStopButton release]; [_cancelButton release]; [_timedButton release]; [_imagePickerController release]; AudioServicesDisposeSystemSoundID(_tickSound); [_cameraTimer release]; [_tickTimer release]; [super dealloc]; } - (void)setupImagePicker:(UIImagePickerControllerSourceType)sourceType { self.imagePickerController.sourceType = sourceType; if (sourceType == UIImagePickerControllerSourceTypeCamera) { self.imagePickerController.showsCameraControls = NO; if ([[self.imagePickerController.cameraOverlayView subviews] count] == 0) { CGRect overlayViewFrame = self.imagePickerController.cameraOverlayView.frame; CGRect newFrame = CGRectMake(0.0, CGRectGetHeight(overlayViewFrame) - self.view.frame.size.height - 10.0, CGRectGetWidth(overlayViewFrame), self.view.frame.size.height + 10.0); self.view.frame = newFrame; [self.imagePickerController.cameraOverlayView addSubview:self.view]; } } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; [self.cameraTimer invalidate]; _cameraTimer = nil; [self.tickTimer invalidate]; _tickTimer = nil; } - (void)finishAndUpdate { [self.delegate didFinishWithCamera]; self.cancelButton.enabled = YES; self.takePictureButton.enabled = YES; self.timedButton.enabled = YES; self.startStopButton.enabled = YES; self.startStopButton.title = @"Start"; } #pragma mark - #pragma mark Camera Actions - (IBAction)done:(id)sender { if (![self.cameraTimer isValid]) [self finishAndUpdate]; } - (IBAction)timedTakePhoto:(id)sender { self.cancelButton.enabled = NO; self.takePictureButton.enabled = NO; self.timedButton.enabled = NO; self.startStopButton.enabled = NO; if (self.cameraTimer != nil) [self.cameraTimer invalidate]; _cameraTimer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(timedPhotoFire:) userInfo:[NSNumber numberWithInt:kOneShot] repeats:YES]; if (self.tickTimer != nil) [self.tickTimer invalidate]; _tickTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(tickFire:) userInfo:nil repeats:YES]; } - (IBAction)takePhoto:(id)sender { [self.imagePickerController takePicture]; } - (IBAction)startStop:(id)sender { if ([self.cameraTimer isValid]) { [self.cameraTimer invalidate]; _cameraTimer = nil; [self finishAndUpdate]; } else { self.startStopButton.title = @"Stop"; self.cancelButton.enabled = NO; self.timedButton.enabled = NO; self.takePictureButton.enabled = NO; _cameraTimer = [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(timedPhotoFire:) userInfo:[NSNumber numberWithInt:kRepeatingShot] repeats:YES]; [self.cameraTimer fire]; } } #pragma mark - #pragma mark Timer - (void)timedPhotoFire:(NSTimer *)timer { [self.imagePickerController takePicture]; NSInteger cameraAction = [self.cameraTimer.userInfo integerValue]; switch (cameraAction) { case kOneShot: { [self.cameraTimer invalidate]; _cameraTimer = nil; [self.tickTimer invalidate]; _tickTimer = nil; break; } case kRepeatingShot: { break; } } } - (void)tickFire:(NSTimer *)timer { AudioServicesPlaySystemSound(self.tickSound); } #pragma mark - #pragma mark UIImagePickerControllerDelegate - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage]; if (self.delegate) [self.delegate didTakePicture:image]; if (![self.cameraTimer isValid]) [self finishAndUpdate]; } - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { [self.delegate didFinishWithCamera]; } @end
- PhotoPicker.zip (57 KB)
- 下载次数: 263
发表评论
-
Error watching file for changes: EMFILE
2016-12-15 11:57 1299执行npm start后报错: Error watc ... -
CocoaPods升级1.1.1报错
2016-12-15 08:39 793ERROR: While executing gem .. ... -
Visual Studio Code运行React Native报错
2016-06-13 09:43 1612React Native:0.27.2 React:15 ... -
React Native 0.27.2编译报错this._nativeModule.addListener is not a function
2016-06-12 15:21 3854React Native:0.27.2 React:15 ... -
Unable to resolve module ReactDefaultPerf from
2016-06-02 13:04 2782package.json信息如下: "reac ... -
React Native 0.26.2编译报错Undefined symbols for architecture x86_64
2016-05-26 11:15 2014React Native:0.26.2 React:15. ... -
Failed to update auto layout status: Failed to load designables from path (null)
2016-04-05 22:11 1714确保CocoaPods是0.36.1以上版本,然后在podf ... -
集成微信支付出现Undefined symbols for architecture x86_64错误
2016-03-21 13:22 1751Undefined symbols for architec ... -
React Native热部署之CodePush
2016-01-10 22:27 6239本文使用的环境是Mac OS 10.11.1、Xcode ... -
浅谈React Native中的FlexBox布局
2015-11-17 18:38 4304React Native通过一个基于FlexBox的布局引 ... -
React Native之构建一个简单的列表页
2015-10-23 14:45 2160本文中我们将创建一个简单的电影应用,这个应用将从Rotten ... -
React Native之环境搭建
2015-10-20 16:30 1445本文使用的环境是Mac O ... -
获取图片属性的方法
2015-10-18 20:43 3142很多时候我们需要获 ... -
NSCache的下标用法
2015-09-18 00:19 1213NSCache类和NSDictionary类很相似,也提供 ... -
如何给category添加属性
2015-08-16 10:41 690主要是使用了runtime中的associative机制。 ... -
UITableView的两种重用Cell方法的区别
2015-08-10 13:07 16145UITableView中有两种重用Cell的方法: - ... -
SDImageCache.m报错Unused variable 'fileName'
2015-08-04 21:56 1172GCC手册中的相关解释: unused:This att ... -
Swift调用Objective-C
2015-07-13 23:33 1224Swift调用Objective-C需要一个名为<工程 ... -
使用GCD实现倒计时
2015-07-24 21:47 1083__block int timeout = 60; // ... -
导航栏加分割线的实现
2015-07-01 22:00 1761self.view.backgroundColor = [U ...
相关推荐
在iOS应用开发中,利用相机功能为用户提供拍照和自定义拍照界面是常见的需求。这篇教程将深入探讨如何在iOS平台上实现这些功能。首先,我们从系统相机的使用开始。 一、使用系统相机 1. 请求权限:在iOS 10及以上...
首先,我们要创建一个自定义的拍照页面。这通常通过集成`UIImagePickerController`类来实现,它是苹果提供的用于拍摄照片或录制视频的UI组件。为了自定义这个页面,我们需要设置`UIImagePickerController`的代理,并...
本示例项目"iOS 系统相册调取及自定义相册"旨在帮助开发者了解如何实现这一功能,同时提供对相册界面和相机页面进行自定义的可能性。通过深入理解以下知识点,你将能够构建自己的照片选择器并按照应用程序的视觉风格...
你可以设置相机模式(拍照或录像)、是否显示相册选项,以及处理捕获的图像或视频的数据回调。例如,你可以通过以下代码打开相机: ```swift let imagePickerController = UIImagePickerController() ...
总之,实现“ios-模仿微信发朋友圈信息时,从相册或拍照选择图片,支持图片浏览和删除”的功能,需要掌握多媒体选择、图片处理、手势识别、自定义视图和用户交互等多方面的iOS开发知识。通过以上步骤,你可以构建出...
而在iOS中,可以使用UIImagePickerController类来实现同样的功能,设置其sourceType为UIImagePickerControllerSourceTypeCamera,然后展示相机界面让用户拍照。 其次,模仿微信的UI特效主要涉及以下几个方面: 1. ...
选择图片、拍照和视频上传的功能,这通常涉及到UIImagePickerController的使用。UIImagePickerController是苹果提供的一个控制器,用于让用户从相册中选择图片或视频,或者直接通过摄像头拍摄。开发者需要处理相应的...
3. **自定义相机界面**:为了在拍照时实时预览并应用滤镜,开发者可能创建了一个自定义的相机界面。这通常涉及到捕获摄像头的实时视频流,将其转换为CIImage对象,然后应用滤镜,最后显示在屏幕上。这个过程需要对...
在实现过程中,通常会调用系统提供的API,如Android的`Intent.ACTION_PICK`和`CameraSourcePreview`,或是iOS的`UIImagePickerController`,来打开相册或启动相机。 支付功能(如支付宝支付/微信支付)的集成则更...