当前位置:首页 > 操作系统 > Ios

代码截屏与触摸事件常用函数(iOS)

代码截屏分五步:

首先在视图控制器上创建一个视图

UIView *aView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];
aView.backgroundColor = [UIColor blackColor];[self.view addSubview:aView];[aView release];


1.设置要截屏的图片大小  UIGraphicsBeginImageContext(aView.frame.size);

2. 对哪个视图截图固定大小的图片  [aView.layer renderInContext:UIGraphicsGetCurrentContext()];

3. 获取截屏对象  UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

4. 结束绘制图片

UIGraphicsEndImageContext();

5. 保存到相册  UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);



UI中触摸事件常用函数 
当手指离开屏幕时触发 ( 触摸结束 ),如果想要在触摸结束时实现某方法或者功能,写在这个函数里 - ( void )touchesEnded:( NSSet  *)touches withEvent:( UIEvent  *)event

当手指触摸屏幕时触发, 如果想要在触摸屏幕时实现某方法或者功能,写在这个函数里
( void )touchesBegan:( NSSet  *)touches withEvent:( UIEvent  *)event

当触摸被取消时 ( 前提是手指必须触摸屏幕 ),如果想要在触摸屏幕取消时实现某方法或者功能,写在这个函数里 - ( void )touchesCancelled:( NSSet  *)touches withEvent:( UIEvent  *)event

当手指触摸屏幕并且在屏幕内移动时触发 ( 此时手指不离开屏幕 ),如果想要在触摸屏幕移动时实现某方法或者功能,写在这个函数里
- ( void )touchesMoved:( NSSet  *)touches withEvent:( UIEvent  *)event

碰撞检测 ( 查找谁响应 , 从大到小 )
UIApplication -> UIWindow ->UIViewController-> 视图控制器的 view->view 的所有子视图 ( 按添加顺序查找 )
事件响应和碰撞检测顺序相反 (view 能接收 , 不响应 )UILable 用户交互默认是关闭的 ;UIButton 能响应用户交互 ;UIView 不能响应 , 事件向下传递

原文:http://blog.csdn.net/hakusan/article/details/39026015


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!