UIControll in UIScrollView not receiving touch events - ios

I use SevenSwitch in my project. I need to add it into a UIScrollView but it seems that the control can not receive touch events when I add it into scroll view.
I tried sub classing scrollview and overriding below code:
- (BOOL)touchesShouldCancelInContentView:(UIView *)view {
return NO;
}
also added:
self.scrollView.delaysContentTouches = NO;
but still can not receive the touch event. How can I stop scrollview from preventing the UIControl from receiving touches?
Update
I have a tap gesture on my scroll view because I want that when user tap the scroll view I call [self.scrollView endEditing:YES] to close the keyboard. When I remove it the seven switch is working with tap.
I add below code to my tap gesture:
tap.cancelsTouchesInView = NO;
and now the sevenswitch is working with tap but there is problems when make the switch on or off with touch tracking.

I have made sample in which i have sevenswitch inside the scrollview and it's working properly
- (void)viewDidLoad {
[super viewDidLoad];
SevenSwitch *mySwitch = [[SevenSwitch alloc] initWithFrame:CGRectZero];
mySwitch.center = CGPointMake(self.view.bounds.size.width * 0.5, self.view.bounds.size.height * 0.5);
[mySwitch addTarget:self action:#selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
//[self.view addSubview:mySwitch];
mySwitch.on = true;
[_cntView addSubview:mySwitch];
SevenSwitch *mySwitch3 = [[SevenSwitch alloc] initWithFrame:CGRectZero];
mySwitch3.center = CGPointMake(self.view.bounds.size.width * 0.5, self.view.bounds.size.height * 0.5 + 70);
[mySwitch3 addTarget:self action:#selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:mySwitch3];
//self.view.backgroundColor = [UIColor colorWithRed:0.19f green:0.23f blue:0.33f alpha:1.00f];
mySwitch3.thumbTintColor = [UIColor colorWithRed:0.19f green:0.23f blue:0.33f alpha:1.00f];
mySwitch3.activeColor = [UIColor colorWithRed:0.07f green:0.09f blue:0.11f alpha:1.00f];
mySwitch3.inactiveColor = [UIColor colorWithRed:0.07f green:0.09f blue:0.11f alpha:1.00f];
mySwitch3.onTintColor = [UIColor colorWithRed:0.45f green:0.58f blue:0.67f alpha:1.00f];
mySwitch3.borderColor = [UIColor clearColor];
mySwitch3.shadowColor = [UIColor blackColor];
[_cntView addSubview:mySwitch3];
}
- (void)switchChanged:(SevenSwitch *)sender {
NSLog(#"Changed value to: %#", sender.on ? #"ON" : #"OFF");
}
In which _cntView is the main container view which i have placed inside the scrollview , please check if this working for you
Update
As i mention in the comment i didn't getting what you are trying to say with touch tracking but i have made sample with tap gesture in the scrollview which may help
UIScrollView *scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height)];
[scrollview setContentSize:CGSizeMake(self.view.frame.size.width,700)];
[self.view addSubview:scrollview];
SevenSwitch *mySwitch = [[SevenSwitch alloc] initWithFrame:CGRectZero];
mySwitch.center = CGPointMake(self.view.bounds.size.width * 0.5, self.view.bounds.size.height * 0.5);
[mySwitch addTarget:self action:#selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
//[self.view addSubview:mySwitch];
mySwitch.on = true;
[scrollview addSubview:mySwitch];
SevenSwitch *mySwitch3 = [[SevenSwitch alloc] initWithFrame:CGRectZero];
mySwitch3.center = CGPointMake(self.view.bounds.size.width * 0.5, self.view.bounds.size.height * 0.5 + 70);
[mySwitch3 addTarget:self action:#selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
mySwitch3.thumbTintColor = [UIColor colorWithRed:0.19f green:0.23f blue:0.33f alpha:1.00f];
mySwitch3.activeColor = [UIColor colorWithRed:0.07f green:0.09f blue:0.11f alpha:1.00f];
mySwitch3.inactiveColor = [UIColor colorWithRed:0.07f green:0.09f blue:0.11f alpha:1.00f];
mySwitch3.onTintColor = [UIColor colorWithRed:0.45f green:0.58f blue:0.67f alpha:1.00f];
mySwitch3.borderColor = [UIColor clearColor];
mySwitch3.shadowColor = [UIColor blackColor];
[scrollview addSubview:mySwitch3];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(actionSingleTap:)];
singleTap.numberOfTapsRequired = 1;
singleTap.cancelsTouchesInView = NO;
[scrollview addGestureRecognizer:singleTap];
}
- (void)actionSingleTap:(UITapGestureRecognizer *)sender {
NSLog(#"Tap");
}
- (void)switchChanged:(SevenSwitch *)sender {
NSLog(#"Changed value to: %#", sender.on ? #"ON" : #"OFF");
}
I have made all the new code programatically and it detects touch events outside the sevenSwitch and also detect touch/tap on the seven switch also.If you want to make it make scrollview in Storyboard and change the programatic scrollview with the storyboard outlet

- (void)viewDidLoad {
[super viewDidLoad];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(actionSingleTap:)];
singleTap.numberOfTapsRequired = 1;
[self.scrollView addGestureRecognizer:singleTap];
}
- (void)actionSingleTap:(UITapGestureRecognizer *)sender {
CGPoint touchPoint = [sender locationInView:self.scrollView];
NSLog(#"Touch point coordinates are : %f - %f", touchPoint.x , touchPoint.y );
UIView *hitImageView = [self.scrollView hitTest:touchPoint withEvent:nil];
NSLog(#"%#", hitImageView);
switch (hitImageView.tag) {
case 1:
// do something
break;
default:
break;
}
}

Related

How to add UIActivityIndicatorView to the bottom of UITableView, and toggle it on loadings

I have a "scroll to load more" behavior on my UITableView. It starts loading more content when you scroll to the bottom. What I want to achieve is to show a UIActivityIndicatorView at the bottom of the UITableView when service call is in progress, and hide it when new items are added.
What is a good way to solve this problem? I am using Swift but objective-C solutions are also welcome.
I have implemented the same functionality in objective-C
In the cellForRowAtIndexPath
if (indexPath.row == [self.yourArrayData count] - 1)
{
// Call the API
[self loadMoreData:#"all" andPages:[NSString stringWithFormat:#"%ld", (long)pages] AndIsLoadMore:YES];
}
Add loader or design
-(void)addLoaderViewAtBottom {
viewLoader = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height-100, self.view.frame.size.width, 50)];
[viewLoader setBackgroundColor:[UIColor whiteColor]];
[self.view addSubview:viewLoader];
UIActivityIndicatorView *activityIndicator1 = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicator1.center = CGPointMake((SCREEN_SIZE.width/2), 30);
activityIndicator1.alpha = 1.0;
activityIndicator1.hidden = NO;
[viewLoader addSubview:activityIndicator1];
[activityIndicator1 startAnimating];
}
-(void)hideLoaderView {
[UIView animateWithDuration:1
animations:^(void) {
[viewLoader setFrame:CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, 50)];
}];
}
then use this two methods in your API call method. Call addLoaderViewAtBottom when API call starts and call hideLoaderView after getting the responses
Happy coding...
Initialize UIActivityIndicatorView:
#interface MyBulletinVC ()
{
UIActivityIndicatorView *activityLoadMore;
}
-(void)viewDidLoad
{
activityLoadMore = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:(UIActivityIndicatorViewStyleGray)];
}
Check when UITableView is being scrolled and what is the content offset
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
float bottomEdge = scrollView.contentOffset.y + scrollView.frame.size.height;
float tblBottomEdge = _tblBulletin.frame.size.height+_tblBulletin.frame.origin.y;
if (bottomEdge <= tblBottomEdge)
{
return;
}
if (bottomEdge >= scrollView.contentSize.height)
{
[self show_bottom_loader];
}
}
If applicable as per content offset then display loader in footer of table:
-(void)show_bottom_loader
{
_tblBulletin.tableFooterView = [self returnLoaderViewWhileFetchingRecords];
CGPoint newContentOffset = CGPointMake(0, [_tblBulletin contentSize].height - _tblBulletin.bounds.size.height);
[_tblBulletin setContentOffset:newContentOffset animated:YES];
[self getNewsRecords];
}
Hide footer when data is loaded:
-(void)hide_bottom_loader
{
_tblBulletin.tableFooterView = nil;
UIView *v = [[UIView alloc] initWithFrame:CGRectZero];
v.backgroundColor = [UIColor clearColor];
[_tblBulletin setTableFooterView:v];
[activityLoadMore stopAnimating];
}
-(UIView*)returnLoaderViewWhileFetchingRecords
{
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0,0,_tblBulletin.frame.size.width,44)];
view.backgroundColor =[UIColor clearColor];
UILabel *lblBg =[[UILabel alloc]initWithFrame:CGRectMake(0,1,_tblBulletin.frame.size.width,42)];
lblBg.backgroundColor =[UIColor whiteColor];
[view addSubview:lblBg];
UILabel *lbl =[[UILabel alloc]initWithFrame:CGRectMake(_tblBulletin.frame.size.width/2 - 20,0,_tblBulletin.frame.size.width/2,view.frame.size.height)];
lbl.textAlignment = NSTextAlignmentLeft;
lbl.text = #"Loading...";
lbl.font = [UIFont fontWithName:#"Arial" size:14.0f];
lbl.textColor = [UIColor darkGrayColor];
lbl.backgroundColor = [UIColor clearColor];
lbl.userInteractionEnabled = NO;
[view lbl];
activityLoadMore.frame = CGRectMake(_tblBulletin.frame.size.width/2-35,22,0,0);
[activityLoadMore startAnimating];
[view addSubview:activityLoadMore];
return view;
}
-(void)getNewsRecords
{
//fetch new records and add to your array.
[self hide_bottom_loader];
//reload table.
}
Replace tblBulletin with you table name.

UIScrollView paging disabled after rotation

Following is my code for App Tour using UIScrollView with paging enabled using AutoLayout (Masonry) It works fine in Portrait but when I rotate paging gets disabled so it doesn't work in Landscape. Then it doesn't work in Portrait mode either. Can someone help what's wrong here?
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor clearColor];
self.scrollView = [UIScrollView new];
self.scrollView.backgroundColor = [UIColor clearColor];
self.scrollView.scrollEnabled = YES;
self.scrollView.pagingEnabled = YES;
self.scrollView.delegate = self;
self.scrollView.showsHorizontalScrollIndicator = NO;
[self.view addSubview:self.scrollView];
[self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
UIImageView *esImageview1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"CommonResources.bundle/page1"]];
esImageview1.contentMode = UIViewContentModeScaleAspectFit;
esImageview1.backgroundColor = [UIColor clearColor];
esImageview1.userInteractionEnabled = YES;
[self.scrollView addSubview:esImageview1];
[esImageview1 mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.bottom.equalTo(self.scrollView);
make.width.height.equalTo(self.view);
}];
UIImageView *esImageview2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"CommonResources.bundle/page2"]];
esImageview2.contentMode = UIViewContentModeScaleAspectFit;
esImageview2.backgroundColor = [UIColor clearColor];
esImageview2.userInteractionEnabled = YES;
[self.scrollView addSubview:esImageview2];
[esImageview2 mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(esImageview1.mas_right);
make.top.bottom.equalTo(self.scrollView);
make.width.height.equalTo(self.view);
}];
UIImageView *esImageview3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"CommonResources.bundle/page3"]];
esImageview3.contentMode = UIViewContentModeScaleAspectFit;
esImageview3.backgroundColor = [UIColor clearColor];
esImageview3.userInteractionEnabled = YES;
[self.scrollView addSubview:esImageview3];
[esImageview3 mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(esImageview2.mas_right);
make.top.bottom.equalTo(self.scrollView);
make.width.height.equalTo(self.view);
}];
self.pageControl = [UIPageControl new];
self.pageControl.numberOfPages = 3;
self.pageControl.currentPage = 0;
self.pageControl.backgroundColor = [UIColor clearColor];
[self.view addSubview:self.pageControl];
[self.pageControl mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.view);
make.height.equalTo(#40);
make.top.equalTo(self.view).with.offset(40);
}];
UILabel *titleLabel = [UILabel new];
titleLabel.text = #"App Tour";
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.textColor = [UIColor whiteColor];
titleLabel.font = [UIFont fontWithName:#"Helvetica-Light" size:16];
titleLabel.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:titleLabel];
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.view);
make.height.equalTo(#40);
make.top.equalTo(self.view).with.offset(20);
}];
UIButton *doneButton = [UIButton new];
[doneButton.titleLabel setFont:[UIFont fontWithName:#"Helvetica-Light" size:16]];
[doneButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[doneButton setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
[doneButton setTitle:#"Done" forState:UIControlStateNormal];
[doneButton addTarget:self action:#selector(doneButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
doneButton.backgroundColor = [UIColor clearColor];
[self.view addSubview:doneButton];
[doneButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.view);
make.height.equalTo(#40);
make.width.equalTo(#70);
make.top.equalTo(self.view).with.offset(20);
}];
}
- (void)doneButtonPressed:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width*self.pageControl.numberOfPages, self.view.frame.size.height);
}
- (void)scrollViewDidScroll:(UIScrollView *)sender {
CGFloat pageWidth = self.scrollView.frame.size.width;
int page = floor((self.scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
self.pageControl.currentPage = page;
}
I'm guessing its getting covered up by another view or something similar to that. Try subclassing the UIScrollView and implementing the following method to check if its responding to your touches at all.
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(#"OMG TOUCHES WORK, NOW WHAT?");
}
You can easily check if it was getting covered up by forcing it to be in front. Call this line of code in the callback for rotation in the UIViewController containing the UIScrollView. It should fix the problem. You may have to subclass the UIView for the controller and put this method in the didLayoutSubviews method instead, not quite sure, depends on your implementation.
[self.view bringSubViewToFront:self.scrollView];
Also check the frame and bounds before and after rotation and see if anything is out of place looking
I just wanted to reset Scrollview's contentsize in didRotateFromInterfaceOrientation delegate. Not sure why though because when I rotate, videDidLayoutSubview already gets called where I am already reseting content size.
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width*self.pageControl.numberOfPages, self.view.frame.size.height);
}

UILabel not responding to touch event

I am using following code to create my view. My UILabel is inside a scrollview. now i want click event in touchesBegan method of my custom label. but unable to get it.
img1 = [[customLabel alloc] initWithFrame:CGRectMake(0,height ,280,10 )];//
[img1 setText: [self.answer_set objectAtIndex:i]];
[img1 setTextAlignment:NSTextAlignmentLeft];
[img1 setBackgroundColor:[UIColor colorWithRed:127.0f/255.0f green:165.0f/255.0f blue:234.0f/255.0f alpha:1.0f]];
img1.textColor = [UIColor whiteColor];
img1.lineBreakMode = NSLineBreakByWordWrapping;
img1.numberOfLines = 0;
[img1 sizeToFit];
img1.contentMode = UIViewContentModeScaleToFill;
img1.font = [UIFont fontWithName:#"Arial" size:14.0f] ;
CGFloat labelHeight=[self getStringHeightforLabel:img1];
NSLog(#"LABEL HEIGHT:: %f",labelHeight);
//set frame after getting height
if (labelHeight < 60.0) {
labelHeight = 60.0;
}
[img1 setUserInteractionEnabled:YES];
img1.tag = 5000;
img1.frame=CGRectMake(-5,height,285 + 10,labelHeight + 10);
img1.layer.cornerRadius = 5;
/** Shadow */
CALayer *shadowLayer = [[CALayer alloc] init];
shadowLayer.frame = CGRectMake(-5,height ,img1.frame.size.width,img1.frame.size.height);
shadowLayer.cornerRadius = 10;
shadowLayer.backgroundColor = [UIColor blueColor].CGColor;
shadowLayer.shadowColor = [UIColor colorWithRed:127.0f/255.0f green:165.0f/255.0f blue:234.0f/255.0f alpha:1.0f].CGColor;
shadowLayer.shadowOpacity = 0.6;
shadowLayer.shadowOffset = CGSizeMake(0,0);
shadowLayer.shadowRadius = 5;
[img1.layer setMasksToBounds:YES];
[shadowLayer addSublayer:img1.layer];
[self.ans_labels.layer addSublayer:shadowLayer];
height += img1.frame.size.height + 15;
and to get event:
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
UITouch *touch = [touches anyObject];
NSLog(#"worked",nil);
//[self giveAnswer:touch.view.tag];
if(touch.view.tag == 5000){
// do here
}
}
I was able to get event earlier,but not today. what i'm doing wrong ???
yourLabel.userInteractionEnabled = YES;
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(labelTap)];
tapGesture.delegate=self;
[yourLabel addGestureRecognizer:tapGesture];
- (void)labelTap:(UITapGestureRecognizer *)recognize {
}
Finally I ended up with following solution :
1) I added following code to my UIScrollView:
scroll.userInteractionEnabled = YES;
scroll.exclusiveTouch = YES;
scroll.canCancelContentTouches = YES;
scroll.delaysContentTouches = YES;
2) I wanted a touch event, So I added a UIButton over my UILabel of type custom,with clear background color and having same frame size as of label.
3) and last and most important thing, I must have to add UIButton to UIScrollView.
All these give me exact functionality which I wanted.
Try like this
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
[super touchesBegan:touches withEvent:event];
}

UIscrollview and uibuttons tap

I am using a UIScrollView where I got some UIButtons, to recognize that I pressed the button above, I created a subclass of UIScrollView where rewrite the method
- (BOOL) touchesShouldCancelInContentView (UIView *) view
but only enters that method when the touch is a journey, never comes when I press on the screen without more.
the UIScrollView I've created thus:
`
CGSize containerSize = CGSizeMake(320.0f, 480.0f);
CGSize containerSize2 = CGSizeMake(640.0f, 960.0f);
self.scrollView = [[UIScrollViewWithButtons alloc] initWithFrame:(CGRect){.origin=CGPointMake(0.0f, 0.0f), .size=containerSize}];
[self.scrollView setMinimumZoomScale:0.5f];
[self.scrollView setMaximumZoomScale:1.0f];
[self.scrollView setZoomScale:0.5f];
[self.scrollView setDelegate:self];
self.scrollView.bounces = NO;
self.scrollView.bouncesZoom = NO;
self.scrollView.delaysContentTouches = NO;
self.scrollView.userInteractionEnabled = YES;
[self.scrollView setContentInset:UIEdgeInsetsZero];
[self.view addSubview:self.scrollView];
self.containerView = [[UIView alloc] initWithFrame:(CGRect){.origin=CGPointMake(0.0f, 0.0f), .size=containerSize2}];
self.containerView.userInteractionEnabled = YES;
[self.scrollView addSubview:self.containerView];
[self.scrollView setClipsToBounds:NO];
//instanciar uimageview
fondo = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 640, 960)];
[self.containerView addSubview:fondo];
[fondo setImage:[UIImage imageNamed:#"Grande.png"]];
self.scrollView.contentSize = containerSize2;
and button add
imagen = [UIButton buttonWithType:UIButtonTypeCustom];
[imagen addTarget:self action:#selector(pulsadoIzq) forControlEvents:UIControlEventTouchUpInside];
[imagen setTitle:#"" forState:UIControlStateNormal];
[imagen setFrame:CGRectMake(xUser, yUser, 50.0f, 50.0f)];
[imagen setImage:[UIImage imageNamed:#"boton.png"] forState:UIControlStateNormal];
[self.containerView addSubview:fichaUserIzq];
imagen.center = CGPointMake(xUser, yUser);`enter code here`
I need to capture the tap on the screen to the buttons
How I can do?
I would also like to know because if I have implemented this code:
img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:#"img.png"]];
UIPanGestureRecognizer *panRecg = [[UIPanGestureRecognizer alloc]initWithTarget:self action:#selector(imgDragged:)];
img.userInteractionEnabled = YES;
[img addGestureRecognizer:panRecg];
img.center = CGPointMake(160, 436);
[self.scrollView addSubview:img];
When I click on the image nothing happens, does not enter the method, only comes when I press and drag. I also want to capture when pressed over this image and so I capture only when the move.
I solved the problem, I implement this method:
-(void)singleTapGestureCaptured:(UITapGestureRecognizer*)gesture{
CGPoint touchPoint = [gesture locationInView:self.scrollView];
if ((touchPoint.x > 88)&&(touchPoint.x < 226)&&(touchPoint.y > 172)&&(touchPoint.y < 319)) {
if (rodando) {
[self pararAnimacionDado];
}
}
}
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(singleTapGestureCaptured:)];
[scrollView addGestureRecognizer:singleTap];

changing the border color of a label by tapping and dragging

I want to be able to change the border color of my label when it is tapped and dragged and when it is not being tapped and dragged, the border color should return to its previous colour. I have employed both pan and tap gesture recognisers but I have no idea in writing the code to change this. This is my code below:
(void)change:(id)sender {
CGRect labelFrame = CGRectMake(230, 240, 300, 30);
UILabel *headingLabel = [[UILabel alloc] initWithFrame:labelFrame];
headingLabel.layer.borderColor = [UIColor clearColor].CGColor;
headingLabel.layer.borderWidth = 1.0;
headingLabel.backgroundColor = [UIColor blackColor];
headingLabel.textColor = [UIColor redColor];
[self.view addSubview:headingLabel];
[headingLabel setUserInteractionEnabled:YES];
headingLabel.text = _textField.text;
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:#selector(panDetected:)];
[self.view addGestureRecognizer:panRecognizer];
[headingLabel addGestureRecognizer:panRecognizer];
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:#selector(tapDetected:)];
[self.view addGestureRecognizer:tapRecognizer];
[headingLabel addGestureRecognizer:tapRecognizer];
}
(void)panDetected:(UIPanGestureRecognizer *)paramSender{
if (paramSender.state != UIGestureRecognizerStateEnded &&
paramSender.state != UIGestureRecognizerStateFailed){
CGPoint location = [paramSender locationInView:paramSender.view.superview];
paramSender.view.center = location;
}
}
(void) tapDetected:(UITapGestureRecognizer *)paramSender {
NSUInteger touchCounter = 0;
for (touchCounter = 0;
touchCounter < paramSender.numberOfTouchesRequired;
touchCounter++){
CGPoint touchPoint =
[paramSender locationOfTouch:touchCounter
inView:paramSender.view];
}
}
#end
You have to use the view delegate methods :
touchesBegan, touchesEnd..
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIResponder_Class/Reference/Reference.html

Resources