IOS 进度条与手势
//进度条
#import "ViewController.h" @interface ViewController ()
{
UIImageView* _animaImageV;
} @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib. //添加一个动画
NSMutableArray* imageArr = [NSMutableArray new];
for (int i = ; i <= ; i++) {
NSString* stringimage=[NSString stringWithFormat:@"tupian/run%d.tiff",i];
UIImage* aniImage = [UIImage imageNamed:stringimage];
[imageArr addObject:aniImage];
} _animaImageV=[[UIImageView alloc]init];
_animaImageV.frame=CGRectMake(, , , );
_animaImageV.animationImages = imageArr; _animaImageV.animationDuration = 0.1;
[self.view addSubview:_animaImageV];
[self.view bringSubviewToFront:_animaImageV];
[_animaImageV startAnimating]; UISlider* slider=[[UISlider alloc]initWithFrame:CGRectMake(, , , )];
slider.minimumValue=0.1;
slider.maximumValue=3.0;
[slider addTarget:self action:@selector(sliderAct:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:slider]; }
//调用进度条的方法
-(void)sliderAct:(UISlider*)slider{
//编程 安全性 规范
if (_animaImageV.isAnimating) {
[_animaImageV stopAnimating];
}
_animaImageV.animationDuration =slider.value; [_animaImageV startAnimating];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
//手势
//
// ViewController.m
// 单击事件
//
// Created by Ibokan on 15/9/28.
// Copyright (c) 2015年 eoe. All rights reserved.
// #import "ViewController.h" @interface ViewController ()
{
UIImageView* imageView;
}
@end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib. // 添加单个Image
imageView= [[UIImageView alloc]initWithFrame:CGRectMake(, , , )];
UIImage* image = [UIImage imageNamed:@"tupian/run1.tiff"];
imageView.image=image;
//注意:要对ImageView做手势,记得吧用户交互属性设yes
// 因为ImageView不能做手势交互
imageView.userInteractionEnabled=YES;
[self.view addSubview:imageView];
//
NSArray* GesArr=@[@"单击",@"拖拽",@"旋转",@"捏合",@"长按",@"轻扫",@"边缘"];
UISegmentedControl* seg=[[UISegmentedControl alloc]initWithItems:GesArr];
seg.frame=CGRectMake(, , , );
[seg addTarget:self action:@selector(segmentAtion:) forControlEvents:UIControlEventValueChanged];
//设置可选
[seg setEnabled:NO forSegmentAtIndex:];
//自动设配选项的宽度
seg.apportionsSegmentWidthsByContent=YES;
//改变选项颜色
seg.tintColor = [UIColor blackColor];
//设置segment的默认选项
seg.selectedSegmentIndex=;
[self.view addSubview:seg]; }
-(void)segmentAtion:(UISegmentedControl*)segment{
//手势管理
for (UIGestureRecognizer* ges in [imageView gestureRecognizers]) {
[imageView removeGestureRecognizer:ges];
}
switch (segment.selectedSegmentIndex) {
case :
// UITapGestureRecognizer//点击
// UIGestureRecognizer//管全部
{
UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAtion:)];
[imageView addGestureRecognizer:tap]; }break;
case :
{
UIPanGestureRecognizer* pan=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(dragAction:)];
[imageView addGestureRecognizer:pan];
}break;
case :{
UIRotationGestureRecognizer* rotate = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotateAction:)]; [imageView addGestureRecognizer:rotate];
}break;
case :{
UIPinchGestureRecognizer* pinch=[[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchAction:)]; [imageView addGestureRecognizer:pinch];
}break;
case :{
UILongPressGestureRecognizer * longPress=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressAction:)];
[imageView addGestureRecognizer:longPress]; }break;
case :{
UISwipeGestureRecognizer* swipe=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeAction:)];
[imageView addGestureRecognizer:swipe];
}break;
case :{
UIScreenEdgePanGestureRecognizer* scress = [[UIScreenEdgePanGestureRecognizer alloc]initWithTarget:self action:@selector(scressAction:)];
[self.view addGestureRecognizer:scress];
scress.edges=UIRectEdgeLeft;
// scress.edges=UIRectEdgeRight;
}break;
default:
break;
}
}
-(void)tapAtion:(id)sender{
NSLog(@"单击");
// [imageView removeGesture]
NSString* str = [NSString stringWithFormat:@"tupian/run2.tiff"];
UIImage * image2=[UIImage imageNamed:str];
imageView.image=image2;
}
-(void)dragAction:(id)sender{
NSLog(@"拖拽");
//向量translation
UIPanGestureRecognizer* pan=(UIPanGestureRecognizer*)sender; CGPoint translation=[sender translationInView:self.view]; pan.view.center=CGPointMake(pan.view.center.x+translation.x, pan.view.center.y+translation.y);
[pan setTranslation:CGPointZero inView:imageView]; }
-(void)rotateAction:(UIRotationGestureRecognizer*)sender{
NSLog(@"旋转"); sender.view.transform=CGAffineTransformRotate(sender.view.transform, sender.rotation);
sender.rotation=;//旋转的弧度为180 }
-(void)pinchAction:(id)sender{
NSLog(@"捏合"); UIPinchGestureRecognizer* pinch=(UIPinchGestureRecognizer*)sender;
imageView.transform=CGAffineTransformMakeScale(pinch.scale, pinch.scale); }
-(void)longPressAction:(id)sender{
NSLog(@"长");
}
-(void)swipeAction:(id)sender{
NSLog(@"轻扫");
// UISwipeGestureRecognizer* swipe=(UISwipeGestureRecognizer*)sender;
for (UIView* view in [self.view subviews]) {
if ([view isMemberOfClass:[UISegmentedControl class]]) {
UISegmentedControl * seg=(UISegmentedControl*)view;
[seg removeSegmentAtIndex:[seg numberOfSegments]- animated:YES];
//根据操作需要自行调用segment触发方法
seg.selectedSegmentIndex=-;
[self segmentAtion:seg];
}
} }
-(void)scressAction:(id)sender{ UIScreenEdgePanGestureRecognizer* edge=(UIScreenEdgePanGestureRecognizer*)sender; UIView* view=[self.view hitTest:[edge locationInView:edge.view] withEvent:nil];
view.alpha=0.5;
if (UIGestureRecognizerStateBegan==edge.state||UIGestureRecognizerStateChanged==edge.state) {
// 向量获取通过ScreenEdge手势方法
CGPoint translation=[edge translationInView:edge.view];
if (edge.edges==UIRectEdgeLeft)
{
//目标视图的center坐标根据向量translation做改变
imageView.center=CGPointMake(self.view.center.x+translation.x,imageView.center.y);
}
}
else {
[UIView animateWithDuration: animations:^{imageView.center=CGPointMake(self.view.center.x,self.view.center.y);}];
} NSLog(@"边缘");
} //-(void)segementAction:(UISegmentedControl*)segment{
// //手势管理
//
//}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
IOS 进度条与手势的更多相关文章
- iOS:进度条控件的详细使用
进度条控件:UIProcessView:UIView 功能:顾名思义,用来显示下载进度或者传输数据进度. 属性: @property(nonatomic) UIProgressViewStyl ...
- iOS进度条显示
一.实现下载文件进度控制 1.代码示例 1 #import "YYViewController.h" 2 3 @interface YYViewController () 4 @p ...
- ios进度条Demo一个
一个很简单的Dmo.就拿出来分享一下. 一个简单的阴影效果 _progressView.frame = CGRectMake(size.width * progress-size.width, H_H ...
- Xamarin iOS教程之进度条和滚动视图
Xamarin iOS教程之进度条和滚动视图 Xamarin iOS 进度条 进度条可以看到每一项任务现在的状态.例如在下载的应用程序中有进度条,用户可以很方便的看到当前程序下载了多少,还剩下多少.Q ...
- 【原】Github系列之三:开源iOS下 渐变颜色的进度条WGradientProgress
概述 今天我们来实现一个iOS平台上的进度条(progress bar or progress view).这种进度条比APPLE自带的更加漂亮,更加有“B格”.它拥有渐变的颜色,而且这种颜色是动态移 ...
- 【iOS】环形渐变进度条实现
之前有人在找渐变进度条的效果,闲来无事就顺手写了一个,然后画了视图层级,方便讲解. 环境信息: Mac OS X 10.10.3 Xcode 6.3.1 iOS 8.3 效果图: 源码下载地址: ht ...
- iOS 自定义进度条
自定义条形进度条(iOS) ViewController.m文件 #import "ViewController.h" @interface ViewController () @ ...
- iOS 开发技巧-制作环形进度条
有几篇博客写到了怎么实现环形进度条,大多是使用Core Graph来实现,实现比较麻烦且效率略低,只是一个小小的进度条而已,我们当然是用最简单而且效率高的方式来实现. 先看一下这篇博客,博客地址:ht ...
- iOS之小功能模块--彩虹动画进度条学习和自主封装改进
前言: 首先展示一下这个iOS小示例的彩色进度条动画效果: 阅读本文先说说好处:对于基础不好的读者,可以直接阅读文末尾的"如何使用彩虹动画进度条"章节,然后将我封装好的这个功能模块 ...
随机推荐
- FCKeditor 2.6.4.1 初始化值不能显示中文问题
最近在学习PHP加入FCKeditor 在线编辑器,发现在初始化Value赋值时,英文可以显示出来,中文怎么都显示不出来,连乱码都不显示. 经过漫长的探索,终于找到原因了! 在fckeditor目录下 ...
- 把自己主要在做的几个工程都传到了GitHub上
GitHub链接 https://github.com/MichaelSuen-thePointer 里面有4个项目,一个是我的C大程大作业,一个3600+行的字典程序,已经弃坑不再更新 还有一个叫w ...
- AsynTask用法
http://blog.csdn.net/liuhe688/article/details/6532519 在Android中实现异步任务机制有两种方式,Handler和AsyncTask. Hand ...
- “请运行Chkdsk工具”怎么解决
今天重新系统,想从移动硬盘中拷贝数据,但是老是提示:“请运行Chkdsk工具” 于是在百度搜索一下,有人提供的解决方案很不错,在些引用一下,以备忘! 电脑上经常遇到这样的提示“某某某文件已损坏且无法读 ...
- Struts2中的异常处理
因为在Action的execute方法声明时就抛出了Exception异常,所以我们无需再execute方法中捕捉异常,仅需在struts.xml 中配置异常处理. 为了使用Struts2的异常处理机 ...
- VBS在指定范围内生成不重复的随机数
Dim Z()ReDim Z(15)For i=0 To UBound(Z) Z(i)=GetRndNum(i-1,UBound(Z)) WScript.Echo Z(i)Next Fun ...
- 【转】Using Gamma 2.2
This is a detailed description of the work with Gamma 2.2. If you are only interested in exact instr ...
- canvas画随机闪烁的星星
canvas画一颗星星: 规则的星星有内切圆和外切圆,每两个点之间的角度是固定的,因此可得到星星的每个点的坐标,画出星星. function drawStars(x,y,radius1,radius2 ...
- SQL笔记-第五章,函数
一.数学函数 功能 函数名 用法 绝对值 ABS() 指数 POWER() POWER(FWeight,-0.5) 平方根 SQRT() 求随机数 RAND() 舍入到最 ...
- LeetCode344:Reverse String@Python
Write a function that takes a string as input and returns the string reversed. Example: Given s = &q ...