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小示例的彩色进度条动画效果: 阅读本文先说说好处:对于基础不好的读者,可以直接阅读文末尾的"如何使用彩虹动画进度条"章节,然后将我封装好的这个功能模块 ...
随机推荐
- Spring AOP 完成日志记录
Spring AOP 完成日志记录 http://hotstrong.iteye.com/blog/1330046
- 异步编程 z
走进异步编程的世界 - 开始接触 async/await 序 这是学习异步编程的入门篇. 涉及 C# 5.0 引入的 async/await,但在控制台输出示例时经常会采用 C# 6.0 的 $&qu ...
- [HTML] CSS 语法
CSS 实例 CSS 规则由两个主要的部分构成:选择器,以及一条或多条声明: 选择器通常是您需要改变样式的 HTML 元素. 每条声明由一个属性和一个值组成. 属性(property)是您希望设置的样 ...
- 41. Unique Binary Search Trees && Unique Binary Search Trees II
Unique Binary Search Trees Given n, how many structurally unique BST's (binary search trees) that st ...
- 剑指Offer:面试题23——从上往下打印二叉树(java实现)
问题描述: 从上往下打印出二叉树的每个节点,同层节点从左至右打印. 思路: 按照层次遍历的方法,使用队列辅助. 1.将根结点加入队列. 2.循环出队,打印当前元素,若该结点有左子树,则将其加入队列,若 ...
- zk抢主
package com.autonavi.tinfo.t1.traffic.pub.openlr.util; import java.util.Collections;import java.util ...
- 洛谷P3374 【模板】树状数组 1
P3374 [模板]树状数组 1 140通过 232提交 题目提供者HansBug 标签 难度普及/提高- 提交 讨论 题解 最新讨论 题目描述有误 题目描述 如题,已知一个数列,你需要进行下面两 ...
- C++中调用Python脚本
C++中调用Python脚本的意义就不讲了,至少你可以把它当成文本形式的动态链接库, 需要的时候还可以改一改,只要不改变接口, C++的程序一旦编译好了,再改就没那么方便了 先看Python的代码 代 ...
- Shell脚本IF条件判断和判断条件总结
转自:http://m.jb51.net/article/56553.htm 这篇文章主要介绍了Shell脚本IF条件判断和判断条件总结,本文先是给出了IF条件判断的语法,然后给出了常用的判断条件总结 ...
- javascript对象属性的赋值解析
代码如下: function Animal(){} function Dog (age){ this.name = 'fuck you' ; this.age = age } var dog = ne ...