Gestures (3) view moves with gestures

Source: Internet
Author: User

#import "QYCustomView.h"

/*
#define HOR_SWIPE_MIN 20//level, when below this value, do not think he is a sweeping gesture
#define VAR_SWIPE_MAX 40//Vertical, set this error range, if greater than this value, sweep invalid
*/

@implementation Qycustomview

-(ID) Initwithcoder: (Nscoder *) Adecoder
{
self = [super Initwithcoder:adecoder];
if (self) {
Self.backgroundcolor = [Uicolor Purplecolor];
_moveview = [[UIView alloc] Initwithframe:cgrectmake (20, 20, 30, 30)];
_moveview.backgroundcolor = [Uicolor Redcolor];
[Self addsubview:_moveview];
}
return self;
}

When our event starts, this method is called when the finger is actually placed on the screen for touch.
-(void) Touchesbegan: (Nsset *) touches withevent: (Uievent *) event
{
_moveview = [[UIView alloc]initwithframe:cgrectmake (0, 0, 30, 30)];
_moveview.backgroundcolor = [Uicolor Redcolor];
[Self addsubview:_moveview];
}



This method is called when we click on the screen and slide without lifting, so that this method is called continuously.
-(void) touchesmoved: (Nsset *) touches withevent: (Uievent *) event
{
Uitouch *tch = [touches anyobject];
Cgpoint currentpoint = [tch locationinview:self];

CGRect frame = self.moveView.frame;
Self.moveView.center = Currentpoint;

NSLog (@ "%s", __func__);
}



When our event is tuned to the bundle, it is actually called when the finger leaves the screen for touch.
-(void) touchesended: (Nsset *) touches withevent: (Uievent *) event
{

}

/*
//
When our event is canceled, say: Finger click on the screen, suddenly call, this time, the phone priority is very high,
All events should be canceled. This method will be called
-(void) touchescancelled: (Nsset *) touches withevent: (Uievent *) event
//{
NSLog (@ "%s", __func__);
Self.startpoint = Cgpointzero;
//}
*/

/*
Only override Drawrect:if perform custom drawing.
An empty implementation adversely affects performance during animation.
-(void) DrawRect: (cgrect) rect
{
Drawing Code
Self.backgroundcolor = [Uicolor Orangecolor];
}
*/
@end

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.