首页 文章 精选 留言 我的

精选列表

搜索[ios],共10000篇文章
优秀的个人博客,低调大师

从采集方面分析如何快速的开发一个完整的iOS直播app源码

开发一款直播app源码,首先需要采集主播的视频和音频,然后传入流媒体服务器,本篇主要讲解如何采集主播的视频和音频,当前可以切换前置后置摄像头和焦点光标,但是美颜功能还没做,可以看见素颜的你。 基本知识介绍 AVFoundation: 音视频数据采集需要用AVFoundation框架.AVCaptureDevice:硬件设备,包括麦克风、摄像头,通过该对象可以设置物理设备的一些属性(例如相机聚焦、白平衡等) AVCaptureDeviceInput:硬件输入对象,可以根据AVCaptureDevice创建对应的AVCaptureDeviceInput对象,用于管理硬件输入数据。 AVCaptureOutput:硬件输出对象,用于接收各类输出数据,通常使用对应的子类AVCaptureAudioDataOutput(声音数据输出对象)、AVCaptureVideoDataOutput(视频数据输出对象) AVCaptionConnection:当把一个输入和输出添加到AVCaptureSession之后,AVCaptureSession就会在输入、输出设备之间建立连接,而且通过AVCaptureOutput可以获取这个连接对象。 AVCaptureVideoPreviewLayer:相机拍摄预览图层,能实时查看拍照或视频录制效果,创建该对象需要指定对应的AVCaptureSession对象,因为AVCaptureSession包含视频输入数据,有视频数据才能展示。 AVCaptureSession: 协调输入与输出之间传输数据 系统作用:可以操作硬件设备工作原理:让App与系统之间产生一个捕获会话,相当于App与硬件设备有联系了, 我们只需要把硬件输入对象和输出对象添加到会话中,会话就会自动把硬件输入对象和输出产生连接,这样硬件输入与输出设备就能传输音视频数据。 捕获音视频步骤: 1.创建AVCaptureSession对象 2.获取AVCaptureDevicel录像设备(摄像头),录音设备(麦克风),注意不具备输入数据功能,只是用来调节硬件设备的配置。 3.根据音频/视频硬件设备(AVCaptureDevice)创建音频/视频硬件输入数据对象(AVCaptureDeviceInput),专门管理数据输入。 4.创建视频输出数据管理对象(AVCaptureVideoDataOutput),并且设置样品缓存代理(setSampleBufferDelegate)就可以通过它拿到采集到的视频数据 5.创建音频输出数据管理对象(AVCaptureAudioDataOutput),并且设置样品缓存代理(setSampleBufferDelegate)就可以通过它拿到采集到的音频数据 6.将数据输入对象AVCaptureDeviceInput、数据输出对象AVCaptureOutput添加到媒体会话管理对象AVCaptureSession中,就会自动让音频输入与输出和视频输入与输出产生连接. 7.创建视频预览图层AVCaptureVideoPreviewLayer并指定媒体会话,添加图层到显示容器layer中 8.启动AVCaptureSession,只有开启,才会开始输入到输出数据流传输。视频采集额外功能一(切换摄像头) 切换摄像头步骤 1.获取当前视频设备输入对象 2.判断当前视频设备是前置还是后置 3.确定切换摄像头的方向 4.根据摄像头方向获取对应的摄像头设备5.创建对应的摄像头输入对象 6.从会话中移除之前的视频输入对象 7.添加新的视频输入对象到会话中。视频采集额外功能二(聚焦光标) 聚焦光标步骤 1.监听屏幕的点击 2.获取点击的点位置,转换为摄像头上的点,必须通过视频预览图层(AVCaptureVideoPreviewLayer)转 3.设置聚焦光标图片的位置,并做动画 4.设置摄像头设备聚焦模式和曝光模式(注意:这里设置一定要锁定配置lockForConfiguration,否则报错)

优秀的个人博客,低调大师

IOS 粒子发射器,雪花落下、创建火焰、河流、蒸汽的动画效果源代码

学习神奇的粒子发射器,雪花纷纷落下的动画效果,就是通过CAEmitterLayer来实现的,这个layer还能创建火焰,河流,蒸汽的动画效果,常用于游戏开发。 原文来自code4app http://www.code4app.com/blog-927904-1776.html Creating your emitter layer let rect = CGRect(x: 0.0, y: -70.0, width: view.bounds.width, height: 50.0) let emitter = CAEmitterLayer() emitter.backgroundColor = UIColor.blueColor().CGColor emitter.frame = rect emitter.emitterShape = kCAEmitterLayerRectangle view.layer.addSublayer(emitter) 代码创建了CAEmitterLayer,并设置了发射源形状emitterShape。 有几个常用的emitterShape: kCAEmitterLayerPoint:使所有粒子在同一点创建发射器的位置。这是一个很好的选择用于火花或烟花,比如,你可以创建一个火花效应,通过创建所有的粒子在同一点上,使它们在不同的方向飞,然后消失。 kCAEmitterLayerLine:所有粒子沿发射架顶部的顶部。这是一个用于瀑布效应的发射极的形状;水粒子出现在瀑布的顶部边缘。 kCAEmitterLayerRectangle:创建粒子随机通过一个给定的矩形区域。 Adding an emitter frame 前面是设置了layer Frame,下面设置layer里面的Emitter的frame emitter.emitterPosition = CGPoint(x: rect.width * 0.5, y: rect.height * 0.5) emitter.emitterSize = rect.size 代码设置了Emitter中心点是layer的中心点,size和layer一样。 []Creating an emitter cell 现在,您已经配置了发射器的位置和大小,可以继续添加Cell。 Cell是表示一个粒子源的数据模型。是CAEmitterLayer一个单独的类,因为一个发射器可以包含一个或多个粒子。 例如,在一个爆米花动画,你可以有三种不同的细胞代表一个爆米花的不同状态:完全炸开,一半炸开和没有炸开: let emitterCell = CAEmitterCell() emitterCell.contents = UIImage(named: "flake.png")!.CGImage emitterCell.birthRate = 20 emitterCell.lifetime = 3.5 emitter.emitterCells = [emitterCell] 代码每一秒创建20个cell,每个cell有3.5s的生命周期,之后一些cell就会消失 []Controlling your particles 上面设置的cell不会动,需要给它个加速度 emitterCell.xAcceleration = 10.0 emitterCell.yAcceleration = 70.0 设置Cell在X轴,Y轴的加速度。 emitterCell.velocity = 20.0 // x-y平面的发射方向 // -M_PI_2 垂直向上 emitterCell.emissionLongitude = CGFloat(-M_PI_2) 设置起始速度,发射的方向是通过emissionLongitude属性定义的。 []Adding randomness to your particles emitterCell.velocityRange = 200.0 设置其实速度的随机范围,每个粒子的速度将是一个随机值之间(20-200)= 180 ~(20 + 200)= 220。负初始速度的粒子不会向上飞,一旦出现在屏幕上,他们就会开始浮动。带正速度的粒子先飞起来,然后再浮。 emitterCell.emissionRange = CGFloat(M_PI_2) 原来,你配置的所有粒子射直线上升(π/ 2角)作为他们的出现。上面这行代码表示为每个粒子随机选一个发射角度在(-π/2 + π/2)= 180度(-π/ 2 +π/2)= 0度之间。 []Changing particle color 设置你的粒子颜色 emitterCell.color = UIColor(red: 0.9, green: 1.0, blue: 1.0, alpha: 1.0).CGColor 还可以设置粒子的颜色RGB范围: emitterCell.redRange = 0.1 emitterCell.greenRange = 0.1 emitterCell.blueRange = 0.1 由于RGB最大为1.0,所以red是取值0.81.0,green:0.91.0,blue:0.9~1.0 []Randomizing particle appearance 之前的粒子都是一样大的,这里给粒子分配一个随机大小。 emitterCell.scale = 0.8 emitterCell.scaleRange = 0.8 设置粒子是原来的80%大小,随机范围是从0.0到1.6。 emitterCell.scaleSpeed = -0.15 粒子每秒钟按15%的体积缩小。 还可以设置透明度 emitterCell.alphaRange = 0.75 emitterCell.alphaSpeed = -0.15 透明度 0.25~1.0,每秒透明度减少15%。

优秀的个人博客,低调大师

iOS-《编写高质量代码》笔记-第七章 设计模式与Cocoa编程

建议45:设计模式是特定环境下的特定问题的解决方案 设计模式是某种特定设计的模板或指导原则。 建议46:MVC模式是一种复合或聚合模式 MVC 是一种高级别的模式,关注的是应用程序的全局架构,并根据各种对象在程序中发挥的作用对其进行分类。 建议47:对象建模在数据库中也广泛使用 看不懂 建议48:类簇可简化框架的公开架构而又不减少功能的丰富性 1.类簇(class cluster)基于抽象工厂设计模式。 2.类簇,可以用于隐藏实现的具体细节,为调用者提供一个简单的接口。 3.类簇也可以有多个基类,如NSArray、NSMutableArray,后者就是继承的前者。对一些“大同小异”的问题,往往会有不错的结果。 这个架构的用户只看到一个公共类,即NSNumber。

优秀的个人博客,低调大师

[IOS]包含增删改查移动的tableView展示+plist文件保存+程序意外退出保存Demo

做一个tableView,包含增删改移动功能,并且修改值的时候,在按home键的时候会自动保存。如果可以的话使者保存自定义的类数组保存到plist中。 实现步骤: 1.创建一个SingleViewApplication的项目,首页命名为FirstViewController FirstViewController.h: #import <UIKit/UIKit.h> @interface FirstViewController : UITableViewController @property(nonatomic,retain) NSMutableArray *array; @end FirstViewController.m: #import "FirstViewController.h" #import "DXWViewController.h" @interface FirstViewController () @end NSString *CellIdentifier = @"Cell"; @implementation FirstViewController - (id)initWithStyle:(UITableViewStyle)style { self = [super initWithStyle:style]; if (self) { self.array = @[ [[DXWViewController alloc] initWithStyle:UITableViewStylePlain]]; self.title = @"目录列表"; } return self; } - (void)viewDidLoad { [super viewDidLoad]; [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:CellIdentifier]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.array count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; int row = [indexPath row]; cell.textLabel.text = ((DXWViewController *)self.array[row]).title; //有右边的>符号 cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { int row = [indexPath row]; [self.navigationController pushViewController:self.array[row] animated:YES]; } @end 2.创建二级子视图控制器,不带xib文件,命名DXWViewController DXWViewController.h: #import <UIKit/UIKit.h> @protocol change <NSObject> -(void)changeData:(int)row Name:(NSString *)name; @end @interface DXWViewController : UITableViewController<UIAlertViewDelegate> @property(nonatomic,retain)NSMutableArray *array; @property(retain,nonatomic)NSIndexPath *indexPath; @end DXWViewController.m: #import "DXWViewController.h" #import "EditViewController.h" BOOL RIGHTBUTTON; @interface DXWViewController () @end @implementation DXWViewController //获取沙盒文件路径 -(NSString *)getPath { //用来获得Document地址 NSArray *arr = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);//注意:这里是NSDocument不是NSDocumentation,特别注意 NSLog(@"%@",arr); //在地址上增加文件 NSString *path = [arr[0] stringByAppendingPathComponent:@"abc.plist"]; NSLog(@"%@",path); return path; } -(BOOL)writeDataToFile:(NSString *)path DataSource:(NSMutableArray *)array { return [array writeToFile:path atomically:YES]; } -(NSMutableArray *)getDataFromFile:(NSString *)path { //判断是否有文件 if([[NSFileManager defaultManager] fileExistsAtPath:[self getPath]]) { NSMutableArray *arr = [NSArray arrayWithContentsOfFile:[self getPath]]; return arr; } } - (id)initWithStyle:(UITableViewStyle)style { self = [super initWithStyle:style]; if (self) { self.title = @"子视图"; // NSArray *arr = @[@"返回上一级",@"小花",@"小李",@"小王",@"小丁",@"小张",@"小康",@"小刘",@"小墩",@"大墩"]; // self.array = [arr mutableCopy]; // if ([self writeDataToFile:[self getPath] DataSource:self.array]) { // NSLog(@"success"); // } //获取数据 self.array = [self getDataFromFile:[self getPath]]; } return self; } - (void)viewDidLoad { [super viewDidLoad]; //首先要添加右上角的一个edit按钮,按钮按下去可以设置可以编辑 UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithTitle:@"添加" style:UIBarButtonItemStyleBordered target:self action:@selector(itemLeftButtonClick:)]; self.navigationItem.leftBarButtonItem = button; UIBarButtonItem *button1 = [[UIBarButtonItem alloc] initWithTitle:@"删除" style:UIBarButtonItemStyleBordered target:self action:@selector(itemRightButtonClick:)]; self.navigationItem.rightBarButtonItem = button1; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.array count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *identifier = @"Identifier"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; } int row = [indexPath row]; cell.textLabel.text = self.array[row]; return cell; } -(void)itemLeftButtonClick:(id)sender { //设置可以编辑 RIGHTBUTTON = false; [self.tableView setEditing:!self.tableView.editing];//设置成和当前状态相反的状态 if (self.tableView.editing) { [self.navigationItem.leftBarButtonItem setTitle:@"完成"]; } else { [self.navigationItem.leftBarButtonItem setTitle:@"添加"]; } } -(void)itemRightButtonClick:(id)sender { RIGHTBUTTON = true; //设置可以编辑 [self.tableView setEditing:!self.tableView.editing];//设置成和当前状态相反的状态 if (self.tableView.editing) { [self.navigationItem.rightBarButtonItem setTitle:@"完成"]; } else { [self.navigationItem.rightBarButtonItem setTitle:@"删除"]; } } //设置编译图标 -(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { //删除 if (RIGHTBUTTON) { return UITableViewCellEditingStyleDelete; } else { return UITableViewCellEditingStyleInsert; //return UITableViewCellEditingStyleNone; } } //设置是否可以移动 -(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { if (RIGHTBUTTON) { return NO; } else { if (indexPath != 0) { return YES; } } } -(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { if ([indexPath row] == 0) { return NO; } else { return YES; } } //实现UIAlertView代理协议 -(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { //获取AlertView中的数据 NSString *str = [alertView textFieldAtIndex:0].text; //将数据插入到array数组中(位置是点击的位置的下一行) [self.array insertObject:str atIndex:[self.indexPath row]+1]; //用点击位置的下一行创建一个新的NSIndexPath int newrow = [self.indexPath row]+1; NSIndexPath *index = [NSIndexPath indexPathForRow:newrow inSection:0]; //在tableView的这个NSIndexPath中插入数据 [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:index] withRowAnimation: UITableViewRowAnimationFade]; [self writeDataToFile:[self getPath] DataSource:self.array]; } -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { //删除按钮 if (RIGHTBUTTON) { if ([indexPath row] != 0) { int row = [indexPath row]; [self.array removeObjectAtIndex:row]; [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationMiddle]; [self writeDataToFile:[self getPath] DataSource:self.array]; } } //添加按钮 else { //获得点击的indexPath self.indexPath = indexPath; //创建一个UIAlertView,用来获得数据 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"enterstring" message:nil delegate:self cancelButtonTitle:@"ok" otherButtonTitles: nil]; //带有输入框的UIAlertView alert.alertViewStyle = UIAlertViewStylePlainTextInput; [alert show]; } } //可以根据行来设置delete按钮位置上button的标题 -(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath { return @"你删我一个试试"; } -(void)dealloc { [self.array release]; [self.indexPath release]; [super dealloc]; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if ([indexPath row] == 0) { [self.navigationController popToRootViewControllerAnimated:YES]; } else { EditViewController *edit = [[EditViewController alloc] init]; edit.sname = self.array`indexPath row`; edit.row = indexPath.row; edit.delegate = self; [self.navigationController pushViewController:edit animated:YES]; } //蓝色背景消失 [tableView deselectRowAtIndexPath:indexPath animated:YES]; } -(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath { if (!RIGHTBUTTON) { if ([destinationIndexPath row]!=0) { id object= self.array`sourceIndexPath row`; [self.array removeObject:self.array`sourceIndexPath row`]; [self.array insertObject:object atIndex:[destinationIndexPath row]]; NSLog(@"%d",[self.array count]); NSLog(@"当前位置%d,目标位置%d",[sourceIndexPath row],[destinationIndexPath row]); [self writeDataToFile:[self getPath] DataSource:self.array]; } //如果是跟第一行移动,则不允许这样操作,重新加载数据 [self.tableView reloadData]; } } //实现遵循协议的方法 -(void)changeData:(int)row Name:(NSString *)name { [self.array replaceObjectAtIndex:row withObject:name]; [self writeDataToFile:[self getPath] DataSource:self.array]; [self.tableView reloadData]; } @end 3.创建一个可以修改的viewController With xib,命名为:EditViewController EditViewController.h: #import <UIKit/UIKit.h> #import "DXWViewController.h" @interface EditViewController : UIViewController @property (retain, nonatomic) IBOutlet UITextField *name; @property(retain,nonatomic)NSString *sname; @property(assign,nonatomic) int row; - (IBAction)assignBoardClick:(id)sender; @property(nonatomic,retain)id<change>delegate; @end EditViewController.m: #import "EditViewController.h" #import "DXWViewController.h" @interface EditViewController () @end @implementation EditViewController //获取沙盒文件路径 -(NSString *)getPath { //用来获得Document地址 NSArray *arr = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);//注意:这里是NSDocument不是NSDocumentation,特别注意 NSLog(@"%@",arr); //在地址上增加文件 NSString *path = [arr[0] stringByAppendingPathComponent:@"abc.plist"]; NSLog(@"%@",path); return path; } - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { self.title = @"信息修改"; } return self; } -(void)viewWillAppear:(BOOL)animated { self.name.text = self.sname; } - (void)viewDidLoad { [super viewDidLoad]; //首先要添加右上角的一个edit按钮,按钮按下去可以设置可以编辑 UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStyleBordered target:self action:@selector(itemLeftButtonClick:)]; //左按钮返回 self.navigationItem.leftBarButtonItem = button; //右按钮编辑保存并返回 UIBarButtonItem *button1 = [[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStyleBordered target:self action:@selector(itemRightButtonClick:)]; self.navigationItem.rightBarButtonItem = button1; //实现不按保存按钮也能够保存到文件的功能,获取应用 UIApplication *app = [UIApplication sharedApplication]; //在通知中心添加一个观察者,当符合UIApplicationWillResignActiveNotification条件时,调用方法 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(save:) name:UIApplicationWillResignActiveNotification object:app]; } -(void)save:(id)sender { self.sname = self.name.text; if ([self.delegate respondsToSelector:@selector(changeData:Name:)]) { [self.delegate changeData:self.row Name:self.sname]; } } //返回 -(void)itemLeftButtonClick:(id)sender { [self.navigationController popViewControllerAnimated:YES]; } //保存 -(void)itemRightButtonClick:(id)sender { [self changedata]; [self.navigationController popViewControllerAnimated:YES]; } - (void)changedata { self.sname = self.name.text; if ([self.delegate respondsToSelector:@selector(changeData:Name:)]) { [self.delegate changeData:self.row Name:self.sname]; } } - (IBAction)assignBoardClick:(id)sender { [sender resignFirstResponder]; } - (void)dealloc { [_name release]; [super dealloc]; } @end demo源文件: http://download.csdn.net/detail/s10141303/6008305 本文转蓬莱仙羽51CTO博客,原文链接:http://blog.51cto.com/dingxiaowei/1366422,如需转载请自行联系原作者

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

用户登录
用户注册
修改密码
忘记密码