EF练习。IOS中的手势详解。

大红鹰葡京会 1

1、点击

    UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(click)];

    //设置当前需要点击的次数
    [tap setNumberOfTapsRequired:1];
    //设置当前需要触发事件的手指数量
[tap setNumberOfTouchesRequired:2];
//设置当前代理
tap.delegate=self;
[_view addGestureRecognizer:tap];
//触发方法
- (void) click{
    NSLog(@"当前视图被点击了! ");
}

加上实业数据模型

2、长按

UILongPressGestureRecognizer * longPress=[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress)];
//设置当前长按最小的时长
longPress.minimumPressDuration=2;

//设置允许的移动范围
 [longPress setAllowableMovement:2];
[_view addGestureRecognizer:longPress];
//触发方法
- (void) longPress{
    NSLog(@"长按事件触发! ");
}

大红鹰葡京会 2

3、轻扫

UISwipeGestureRecognizer * swip=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipMethod)];
    //往左边方向
  swip.direction=UISwipeGestureRecognizerDirectionLeft  ;
    //往右边方向
  swip.direction=UISwipeGestureRecognizerDirectionRight  ;
    //往上面方向
    swip.direction=UISwipeGestureRecognizerDirectionUp  ;
    //往下面方向
   swip.direction=UISwipeGestureRecognizerDirectionDown  ;
    [_view addGestureRecognizer:swip];

    //触发方法
    - (void) swipMethod{
        NSLog(@"轻扫事件触发! ");
}

  如果波及到2个以上方向的手势最好上加多只UISwipeGestureRecognizer
对象并设置不同的自由化,不要通过下面方式因此符号|来连接:

swip.direction=UISwipeGestureRecognizerDirectionLeft  | UISwipeGestureRecognizerDirectionRight  

下一步

4、拖动

 大红鹰葡京会 3

  第一步:添加视图

_view=[[UIView alloc] initWithFrame:CGRectMake(50, 250, 300, 200)];
[_view setBackgroundColor:[UIColor redColor]];
[self.view addSubview:_view];

  第二步:添加手势

UIPanGestureRecognizer *pan=[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(paned:)];
[_view addGestureRecognizer:pan];

  第三步:实现方式

- (void) paned:(UIPanGestureRecognizer *) pan{

    //获取移动的大小
    CGPoint point= [pan translationInView:pan.view];
    //更改视图的中心点坐标
    CGPoint points=_view.center;
    points.x+=point.x;
    points.y+=point.y;
    _view.center=points;
    //每次都清空一下消除坐标叠加
    [pan setTranslation:CGPointZero inView:pan.view];
}

大红鹰葡京会 4

5、旋转

 大红鹰葡京会 5

  第一步:添加视图

_view=[[UIView alloc] initWithFrame:CGRectMake(50, 250, 300, 200)];
[_view setBackgroundColor:[UIColor redColor]];
[self.view addSubview:_view];

  第二步:添加手势

UIRotationGestureRecognizer * roate=[[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)];
    [_view addGestureRecognizer:roate];
roate.delegate=self;

  第三步:实现方式

- (void) rotate:(UIRotationGestureRecognizer *) rote{
   //获取当前旋转的度数
   CGFloat rotation= rote.rotation;
    //通过仿射变换实现旋转
  _view.transform=CGAffineTransformRotate(_view.transform, rotation);
    //防止旋转叠加需要清零
    rote.rotation=0;
}

 

6、捏合

 大红鹰葡京会 6

  第一步:添加视图

_view=[[UIView alloc] initWithFrame:CGRectMake(50, 250, 300, 200)];
[_view setBackgroundColor:[UIColor redColor]];
[self.view addSubview:_view];

  第二步:添加手势

UIPinchGestureRecognizer * pich=[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(piches:)];
[_view addGestureRecognizer:pich];
pich.delegate=self;

  第三步:实现方式

- (void) piches:(UIPinchGestureRecognizer *) pich{
    //获取比例
    CGFloat scale=pich.scale;
    //通过仿射变换实现缩放
    _view.transform=CGAffineTransformScale(_view.transform, scale, scale);
    //防止比例叠加需要置为1
    pich.scale=1;
 }

 

【补充】如果需要而应多独手势需要再次写代理方

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
    return YES;
}

 

作者:杰瑞教育
出处:http://www.cnblogs.com/jerehedu/ 
正文版权归大红鹰葡京会烟台杰瑞教育科技有限公司和博客园共有,欢迎转载,但未经作者同意要保留这个段子声明,且以文章页面明显位置为有原文连接,否则保留追究法律责任的权利。

 

 下一步

大红鹰葡京会 7

 

大红鹰葡京会 8

大红鹰葡京会 9

 

 

大红鹰葡京会 10

添加web窗体

<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
    </div>
    </form>
</body>

简简单单加加一个操作按钮

namespace WebApplication1
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            familySafetyFirecontrolSystemEntities context = new familySafetyFirecontrolSystemEntities();
            TbUser user = new TbUser();

            user.UserID = "001";
            user.UserEmail = "xy@123.com";
            user.UserName = "xy";
            user.UserPassword = "123456";
            user.UserPhone = "12345678901";
            user.UserTypeID = "1";

            context.TbUser.Add(user);//增加
            // context.Entry<TbUser>(user).State = System.Data.EntityState.Added;//增加
            // context.Entry<TbUser>(user).State = System.Data.EntityState.Deleted;//删除
            // context.Entry<TbUser>(user).State = System.Data.EntityState.Modified//修改

            context.SaveChanges();//保存到数据库

        }
    }
}

 

admin

网站地图xml地图