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小示例的彩色进度条动画效果: 阅读本文先说说好处:对于基础不好的读者,可以直接阅读文末尾的"如何使用彩虹动画进度条"章节,然后将我封装好的这个功能模块 ...
随机推荐
- 约瑟夫(环)问题(Josephus problem)
问题描述:皇帝决定找出全国中最幸运的一个人,于是从全国选拔出 n 个很幸运的人,让这 n 个人围着圆桌进餐,可是怎么选择出其中最幸运的一个人呢?皇帝决定:从其中一个人从 1 开始报数,按顺序数到第 k ...
- Sqoop2入门之导入关系型数据库数据到HDFS上(sqoop2-1.99.4版本)
sqoop2-1.99.4和sqoop2-1.99.3版本操作略有不同:新版本中使用link代替了老版本的connection,其他使用类似. sqoop2-1.99.4环境搭建参见:Sqoop2环境 ...
- tinyxml学习5
读取和设置xml配置文件是最常用的操作,试用了几个C++的XML解析器,个人感觉TinyXML是使用起来最舒服的,因为它的API接口和Java的十分类似,面向对象性很好. TinyXML是一个开源的解 ...
- linux 源码安装
下载源码安装包,一般为.tar.gz格式 解压源码至文件夹,linux终端进入该文件夹,安装只需三步,第四步为扫尾工作: ./configure --prefix=/usr/self/文件夹名称 ...
- 国际化(i18n)
一.国际化开发概述 软件的国际化:软件开发时,要使它能同时应对世界不同地区和国家的访问,并针对不同地区和国家的访问,提供相应的.符合来访者阅读习惯的页面或数据. 国际化(internationaliz ...
- C++ 创建和遍历二叉树
一个简单的创建和遍历二叉树的C++程序,二叉树的其他操作程序待更新. #include <iostream> using namespace std; struct BiTNode{ ch ...
- spring读写分离
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource; public class ChooseData ...
- sql条件中比较性能优化
第一个比第二个性能高. 查询语句意义: 如果codelist中tablecode配置为0时, t.Table_Code = 'SV_RETURN_BILL'不生效. 如果codelist中tablec ...
- angular背景图片问题
如果背景图片是从后台取得的数据,可以按下面的方式使用: ng-style="{'background':'url(http://xxx/{{item.id}})'}" 还需要加上 ...
- VS2013使用EF6连接MySql
前提:a.安装MySql的VS插件(版本请下载最新版) 我用的是:mysql-for-visualstudio-1.1.4 b.安装用于.net连接程序 mysql-connector-net-6. ...