create custom annotation animation ios - ios

I want to create custom annotation animations like in this app:- Easy Taxi iOS. In this app when the user is dragging the map, annotation is lifted a little. Then when dragging is stopped, it falls down from the lifted position with a nice animation.
So far i came to know that, I can use a static image in the center of my screen to show the movement on the map, & when i stop dragging the view(map) i have to build a custom animation for the annotation view.
So far i have implemented this code by which i am manipulating an Image to be hidden or shown on the map View in the center of the screen.
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesMoved:touches withEvent:event];
for (UITouch * touch in touches) {
CGPoint loc = [touch locationInView:self.mapView];
if ([self.mapView pointInside:loc withEvent:event]) {
self.mapKitAnnotationimageView.hidden=NO;
imageCheck=NO;
}
}
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
imageCheck=NO;
self.mapKitAnnotationimageView.hidden=YES;
}
-(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{
if (!imageCheck) {
self.mapKitAnnotationimageView.image=[UIImage imageNamed:#"location"];
imageCheck=YES;
}
}
Any help regarding the custom animation will be greatly appreciated. I need this done in very short span of time.
Thanks for your time.

Related

How to make the sprite move positions when the screen is tapped

I would like my sprite to move from one side of the screen to the other like this:
Before tapped:
http://imgur.com/wIFa3JL
And then after the screen has been tapped:
http://imgur.com/ZtWiE7b
Would it start with something like this:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
Thank you!
I am not quite sure if you want to get the position of your finger when you touch the screen and apply to the sprite's position or just to change the position of the sprite when you touch the screen.
If you want to get your finger's position inside touchesBegan and apply that position to the sprite:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UITouch *touch in touches) {
CGPoint location = [touch locationInView:self];
spriteNode.position = location;
}
}
If you want to just change the sprite's position to the opposite side of the tree every time you touch:
First you need to keep track of which side your sprite is currently. Let's create a BOOL to hold that info:
BOOL isRightSide;
Then, at the beginning, if your sprite start at the right side of the tree, just assign TRUE to the boolean.
Finally, in the touch event:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if (isRightSide) {
//Change to sprite's position to the LEFT side
} else {
//Change to sprite's position to the RIGHT side
}
isRightSide = !isRightSide;
}
I hope this helps =)

How to detect if Touch input intersects uiimageview

Can't seem to find an answer to this one anywhere.
My game starts when the user touches the screen, there is a path that the finger must stay within, if it touches/intersects the edges then I want it to run the method [self gameover].
The edge will be a UIImageView.
Thanks everyone.
I hope you have overridden the touches moved event. check either the user touch intersects your image view like below.
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint point =[touch locationInView:self.view];
if (CGRectContainsPoint(self.imageView.frame, point))
{
//Intersects
[self gameOver];
}
}

Identify the touch moved direction

I am doing the View resize,move and rotate on single touch.
I am trying to find the touch moved direction like,
IF touch moved direction is Horizontal or Vertical then MOve the view.
If touch moved direction is diagonal then resize.
And if touch moved like rotate gesture then rotate the View.
I am able to identify the Horizontal or Vertical direction.
Please suggest me how i can identify the diagonal and rotation.
I guess for rotation, you can simply use this mehod -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event.
And for diagonal, you can compare coordinates of both the points.
For diagonal, you can take help from this post also.
Try This:
TDResizerView
both view rotation and move is available in this
in touch move function, you can identify the direction of move finger like this.
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesMoved:touches withEvent:event];
UITouch *touch = [touches anyObject];
CGPoint current=[touch locationInView:self];
CGPoint last=[touch previousLocationInView:self];
if(current.x>last.x){
NSLog(#">>>>rigth");
}else{
NSLog(#">>>>left");
}
if(current.y>last.y){
NSLog(#">>>>up");
}else{
NSLog(#">>>>down");
}
}

Decrease Touch Area of UIButton

I am trying to decrease the touch area of an UIButton. Is that even possible? When the user touches on the button and drags his touch outside the buttton the touch event should stop immediately when the graphic of the button ends. Unfortunately the area is much bigger than the actual graphic. I found a lot things on how to increase the area but not how to make it smaller.
Thanks for your help.
I came up one solution. You can subclass UIButton and override touchesMoved: so that it recognize the touch to be ended if it was outside of the button. Here is my snippet.
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch * touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self];
if(!CGRectContainsPoint(self.bounds, touchPoint))
{
[super touchesEnded:touches withEvent:event];
}
else
{
[super touchesMoved:touches withEvent:event];
}
}
The drawback of this is that if you go out of the button and come back again, the button will not become active. But otherwise, I think it should work fine.

iOS cancel touch events in certain regions

Is there a way to cancel touch events in certain regions of a view? I have a custom UIView and I only want to process touch events only if they are say 100 pixels from the edges of the screen.
As Justin said, add a custom UIView in interface builder (or programmatically) and add it to the view. let's call that view touchArea. Then in your Viewcontroller.m file, implement the
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
methods (depends on what you're trying to do), and in these do:
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:self.view];
if (CGRectContainsPoint(touchArea.frame, location)) {
//code to execute
}
actually, I think even a CGRect as an instance variable that is placed on the view can work, but the above is how I achieved it.
Assuming you're using Interface Builder, simply take another UIView. Resize it, and place it where you want touch events to occur. Then, have the custom view able to be touch active. Programmatically, I, personally, do not know how to do it.

Resources