change position of imageview with animation - iphone

i want to change position of imageview with animation. it just like draw playing card and it will sets to center anyone here who help me for this.
Code-:
#interface PockerAppViewController : UIViewController
{
UIButton *btn;
UIImageView *cards;
}
#property(nonatomic,retain) IBOutlet UIButton *btn;
#property(nonatomic,retain) IBOutlet UIImageView *cards;
-(IBAction)hidebtn:(id)sender;
-(void)setCards;
#end
--------------------------------.mfile-----------------------------
#implementation PockerAppViewController
#synthesize btn,cards;
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
// Custom initialization
}
return self;
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
cards = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"King.png"]];
//[cards setHidden:TRUE];
}
-(IBAction)hidebtn:(id)sender
{
[btn setHidden:TRUE];
[self setCards];
}
-(void)setCards
{
[cards setFrame:cards.frame];
[UIView beginAnimations:#"Move" context:nil];
[UIView setAnimationDuration:0.3];
[cards setCenter:CGPointMake(60,240)];
[UIView commitAnimations];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
CGPoint pos = [touch locationInView:touch.view];
NSLog(#"X: %f",pos.x);
NSLog(#"X: %f",pos.y)
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
this is my data it help me to solve this problem..

Try something like this:
[URImageView setFrame:CurrentPositionFrame];
[UIView beginAnimations:#"animateTableView" context:nil];
[UIView setAnimationDuration:0.4];
[URImageView setFrame:ToTheNewPositionFrame];
[UIView commitAnimations];
As Till pointed you can also use the Center property:
[UIView beginAnimations:#"animateTableView" context:nil];
[UIView setAnimationDuration:0.4];
[URImageView setCenter:CGPointMake(nPositionX ,nPositionY)];
[UIView commitAnimations];
Thanks Till.

think this could be helpful
http://www.flashgamehole.com/Tong/play-game/en/

Related

Image dragging on a UIScrollView

A UIViewController is called when a user touches an image on a UITableViewCell.
It is called using modalViewController.
On this modalViewController is a UIScrollView, with another UIImageView in the middle, that fetches an image using NSDictionary (passed from the UITableViewCell).
Now, what I wanted to achieve was the ability for the user to drag the image vertically only, such that dragging and releasing a little would cause the image to return to the center with animation. If the user drags it to the extremes, the entire UIScrollView is dismissed and the user returns to the UITableView. I used the following code. The issue here is, and as my name suggests, this code is crude. Is there an elegant way of doing this, without the need of so much calculation?
BOOL imageMoved=NO;
- (void) touchesMoved:(NSSet *)touches
withEvent:(UIEvent *)event {
UITouch * touch = [touches anyObject];
CGPoint pos = [touch locationInView: [UIApplication sharedApplication].keyWindow];
CGRect imageRect = _photoImageView.frame;//_photoImageView object of UIImageView
CGFloat imageHeight = imageRect.size.height;//getting height of the image
CGFloat imageTop=240-imageHeight/2;
CGFloat imageBottom=imageTop+imageHeight;//setting boundaries for getting coordinates of touch.
// Touches that originate above imageTop and below imageBottom are ignored(until touch reaches UIImageView)
if (pos.y>50&&pos.y<430&&pos.y>=imageTop&&pos.y<=imageBottom){//extremes are defined as top and bottom 50 pixels.
imagedMoved=YES;//BOOL variable to hold if the image was dragged or not
NSLog(#"%f", pos.y);
[UIView setAnimationDelay:0];
[UIView animateWithDuration:0.4
animations:^{_photoImageView.frame=CGRectMake(0,pos.y-imageHeight/2,320,200);}
completion:^(BOOL finished){ }];
}
}
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch * touch = [touches anyObject];
CGPoint pos = [touch locationInView: [UIApplication sharedApplication].keyWindow];
if (pos.y>50&&pos.y<430){//if touch has NOT ended in the extreme 50 pixels vertically
[UIView setAnimationDelay:0];//restoring UIImageView to original center with animation
[UIView animateWithDuration:0.4
animations:^{_photoImageView.frame=CGRectMake(0,140,320,200);}
completion:^(BOOL finished){ }];
imagedMoved=NO;//prepare BOOL value for next touch event
}
else if(pos.y<50||pos.y>430)
if(imagedMoved)
[self.photoBrowser exit] ;//exit function(imported from UIScrollViewController) dismisses
//modalView using [self dismissViewControllerAnimated:YES completion:nil];
}
All code here is a modification onto a customized copy of UITapView in MWPhotoBrowser.
Yo, here is a much easier way to do this, more or less an example of what Alessandro stated. I'm not finding the top of the screen but I'm giving the illusion of it.
BCViewController.h
#import <UIKit/UIKit.h>
#interface BCViewController : UIViewController <UIScrollViewDelegate>
#property (weak, nonatomic) IBOutlet UIScrollView *svScroller;
#property (weak, nonatomic) IBOutlet UIImageView *ivFish;
#end
#import "BCViewController.h"
#interface BCViewController (){
UIPanGestureRecognizer *_panGestureRecognizer;
CGPoint _fishOrigin;
}
#end
#implementation BCViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.svScroller.delegate = self;
[self.svScroller setContentSize:self.view.frame.size];
self.svScroller.translatesAutoresizingMaskIntoConstraints = NO;
self.ivFish.userInteractionEnabled = YES;
_panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(handlePanFrom:)];
[self.ivFish addGestureRecognizer:_panGestureRecognizer];
_fishOrigin = self.ivFish.center;
NSLog(#"center %f", self.ivFish.center.x);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)handlePanFrom:(UIPanGestureRecognizer *)recognizer{
// if you want it but not used
CGPoint translation = [recognizer translationInView:recognizer.view];
// if you want it but not used
CGPoint velocity = [recognizer velocityInView:recognizer.view];
CGPoint tempPoint;
if (recognizer.state == UIGestureRecognizerStateBegan) {
} else if (recognizer.state == UIGestureRecognizerStateChanged) {
tempPoint = [recognizer locationInView:self.view];
self.ivFish.center = CGPointMake(175.5, tempPoint.y);
} else if (recognizer.state == UIGestureRecognizerStateEnded) {
CGPoint tempPoint;
tempPoint = [recognizer locationInView:self.view];
if (tempPoint.y < 132) {
[UIView animateWithDuration:.3 delay:0
options:UIViewAnimationOptionCurveEaseOut
animations:^ {
[self.navigationController popViewControllerAnimated:TRUE];
}
completion:NULL];
} else {
[UIView animateWithDuration:.3 delay:0
options:UIViewAnimationOptionCurveEaseOut
animations:^ {
self.ivFish.center = _fishOrigin;
}
completion:NULL];
}
}
}

How to add a magnifier to custom control?

How to add a magnifier to custom control? Control is a child of UIView. (It's a UIWebView - but native magnification functionality doesn't work at some pages.)
UPDATED:
Maybe it's possible to force a draw of magnifier on UIWebView?
1. Add the following files to your project:
MagnifierView.h:
//
// MagnifierView.h
// SimplerMaskTest
//
#import <UIKit/UIKit.h>
#interface MagnifierView : UIView {
UIView *viewToMagnify;
CGPoint touchPoint;
}
#property (nonatomic, retain) UIView *viewToMagnify;
#property (assign) CGPoint touchPoint;
#end
MagnifierView.m:
//
// MagnifierView.m
// SimplerMaskTest
//
#import "MagnifierView.h"
#import <QuartzCore/QuartzCore.h>
#implementation MagnifierView
#synthesize viewToMagnify;
#dynamic touchPoint;
- (id)initWithFrame:(CGRect)frame {
return [self initWithFrame:frame radius:118];
}
- (id)initWithFrame:(CGRect)frame radius:(int)r {
int radius = r;
if ((self = [super initWithFrame:CGRectMake(0, 0, radius, radius)])) {
//Make the layer circular.
self.layer.cornerRadius = radius / 2;
self.layer.masksToBounds = YES;
}
return self;
}
- (void)setTouchPoint:(CGPoint)pt {
touchPoint = pt;
// whenever touchPoint is set, update the position of the magnifier (to just above what's being magnified)
self.center = CGPointMake(pt.x, pt.y-66);
}
- (CGPoint)getTouchPoint {
return touchPoint;
}
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGRect bounds = self.bounds;
CGImageRef mask = [UIImage imageNamed: #"loupe-mask#2x.png"].CGImage;
UIImage *glass = [UIImage imageNamed: #"loupe-hi#2x.png"];
CGContextSaveGState(context);
CGContextClipToMask(context, bounds, mask);
CGContextFillRect(context, bounds);
CGContextScaleCTM(context, 1.2, 1.2);
//draw your subject view here
CGContextTranslateCTM(context,1*(self.frame.size.width*0.5),1*(self.frame.size.height*0.5));
//CGContextScaleCTM(context, 1.5, 1.5);
CGContextTranslateCTM(context,-1*(touchPoint.x),-1*(touchPoint.y));
[self.viewToMagnify.layer renderInContext:context];
CGContextRestoreGState(context);
[glass drawInRect: bounds];
}
- (void)dealloc {
[viewToMagnify release];
[super dealloc];
}
#end
TouchReader.h:
//
// TouchReader.h
// SimplerMaskTest
//
#import <UIKit/UIKit.h>
#import "MagnifierView.h"
#interface TouchReader : UIView {
NSTimer *touchTimer;
MagnifierView *loop;
}
#property (nonatomic, retain) NSTimer *touchTimer;
- (void)addLoop;
- (void)handleAction:(id)timerObj;
#end
TouchReader.m:
//
// TouchReader.m
// SimplerMaskTest
//
#import "TouchReader.h"
#import "MagnifierView.h"
#implementation TouchReader
#synthesize touchTimer;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
self.touchTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:#selector(addLoop) userInfo:nil repeats:NO];
// just create one loop and re-use it.
if (loop == nil) {
loop = [[MagnifierView alloc] init];
loop.viewToMagnify = self;
}
UITouch *touch = [touches anyObject];
loop.touchPoint = [touch locationInView:self];
[loop setNeedsDisplay];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[self handleAction:touches];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[self.touchTimer invalidate];
self.touchTimer = nil;
[loop removeFromSuperview];
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
[self.touchTimer invalidate];
self.touchTimer = nil;
[loop removeFromSuperview];
}
- (void)addLoop {
// add the loop to the superview. if we add it to the view it magnifies, it'll magnify itself!
[self.superview addSubview:loop];
// here, we could do some nice animation instead of just adding the subview...
}
- (void)handleAction:(id)timerObj {
NSSet *touches = timerObj;
UITouch *touch = [touches anyObject];
loop.touchPoint = [touch locationInView:self];
[loop setNeedsDisplay];
}
- (void)dealloc {
[loop release];
loop = nil;
[super dealloc];
}
#end
Based on: http://coffeeshopped.com/2010/03/a-simpler-magnifying-glass-loupe-view-for-the-iphone
2. Add the following images:
Used images on the code:
loupe-hi#2x.png:
loupe-mask#2x.png:
Original but centered images with a shadow (not used at this moment):
loupe-shadow-hi#2x.png:
loupe-shadow-mask#2x.png:
3. Replace the main UIView on your xib-file by TouchReader
The magnifier will work automaticaly except controls that captures touch events themselfs (for example, UIWebView). And the code above doesn't support the images with a shadow. Please add new answer to the qustion if you successfully fix this issue.
UPDATED:
Change the following code to add UIWebView support. UIView should remain UIView.
#interface TouchReader : UILongPressGestureRecognizer
And add a gesture to webView:
TouchReader* gestureMagnifier = [[[TouchReader alloc] initWithTarget:self action:#selector(handleMagnifier:)] autorelease];
gestureMagnifier.webView = editSource;
gestureMagnifier.delegate = self;
gestureMagnifier.minimumPressDuration = 0.5;
[webView addGestureRecognizer:gestureMagnifier];
TouchReader.h:
//- (void)handleAction:(id)timerObj;
-(void) handleGestureAction:(CGPoint)location;
TouchReader.m:
-(void)awakeFromNib
{
UILongPressGestureRecognizer * longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector(handleGesture:)];
[self addGestureRecognizer:longPressGesture];
}
-(void)handleGesture:(UILongPressGestureRecognizer *)longPressGesture
{
CGPoint location = [longPressGesture locationInView:self];
switch (longPressGesture.state) {
case UIGestureRecognizerStateBegan:
self.touchTimer = [NSTimer scheduledTimerWithTimeInterval:0.5
target:self
selector:#selector(addLoop)
userInfo:nil
repeats:NO];
// just create one loop and re-use it.
if(loop == nil){
loop = [[MagnifierView alloc] init];
loop.viewToMagnify = self;
}
loop.touchPoint = location;
[loop setNeedsDisplay];
break;
case UIGestureRecognizerStateChanged:
[self handleGestureAction:location];
break;
case UIGestureRecognizerStateEnded:
[self.touchTimer invalidate];
self.touchTimer = nil;
[loop removeFromSuperview];
loop=nil;
break;
default:
break;
}
}
- (void)addLoop {
// add the loop to the superview. if we add it to the view it magnifies, it'll magnify itself!
[self.superview addSubview:loop];
}
-(void) handleGestureAction:(CGPoint)location
{
loop.touchPoint = location;
[loop setNeedsDisplay];
}
You don't need the touches... methods any more.

iPhone slide-up view controller for audio player controls?

I have a short audio clip that plays when a button is pressed. I want to create a slide-up controller from the bottom that contains a pause/play button and a slider bar displaying the length of the audio. I also want the view behind the controller to remain scrollable while the controller is visible. I believe this excludes using a UIAlertView or UIActionSheetView as both cause the view below to remain static. What is the best way to implement this?
EDIT: i found a helpful tutorial here: http://iosdevelopertips.com/user-interface/sliding-views-on-and-off-screen-creating-a-reusable-sliding-message-widget.html
and I was able to modify this to get something of what I want. However, if I would like to animate using a nib file where/how would i call this?
#import "SlidingMessageController.h"
#interface SlidingMessageController(private)
- (void)hideMsg;
#end
#implementation SlidingMessageController
#pragma mark -
#pragma mark Private Methods
- (void)hideMsg;
{
// Slide the view off screen
CGRect frame = self.frame;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.75];
frame.origin.y = 480;
frame.origin.x = 0;
self.frame = frame;
//to autorelease the Msg, define stop selector
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(animationDidStop:finished:context:)];
[UIView commitAnimations];
}
- (void)animationDidStop:(NSString*)animationID finished:(BOOL)finished context:(void *)context
{
[self removeFromSuperview];
[self release];
}
#pragma mark -
#pragma mark Initialization
- (id)initWithDirection:(int)dir;
//- (id)initWithTitle:(NSString *)title message:(NSString *)msg
{
if (self = [super init])
{
//Switch direction based on slideDirection konstant
switch (dir) {
case kSlideUp: //slideup
// Notice the view y coordinate is offscreen (480)
// This hides the view
// What should I be doing here if I want to get the nib file???
self.frame = CGRectMake(0,480,320, 90);
[self setBackgroundColor:[UIColor blackColor]];
[self setAlpha:.87];
newY = 380;
newX = 0;
myDir = 0;
break;
default:
break;
}
}
return self;
}
#pragma mark -
#pragma mark Message Handling
- (void)showMsgWithDelay:(int)delay
{
// UIView *view = self.view;
CGRect frame = self.frame;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.75];
// Slide up based on y axis
// A better solution over a hard-coded value would be to
// determine the size of the title and msg labels and
// set this value accordingly
frame.origin.y = newY;
frame.origin.x = newX;
self.frame = frame;
[UIView commitAnimations];
// Hide the view after the requested delay
[self performSelector:#selector(hideMsg) withObject:nil afterDelay:delay];
}
#pragma mark -
#pragma mark Cleanup
- (void)dealloc
{
if ([self superview])
[self removeFromSuperview];
[super dealloc];
}
#end
What do you mean with a "slide-up controller"? Just a view that slides up from the bottom? If so, you can just create a UIView with the buttons in it, and animate it. For the animation you can use UIView beginAnimations:context: and commitAnimations.

Objective-c animation block doesn't seem to fire

I have a method in my UIView subclass "Card" to dismiss an instance by fading its alpha from 1 to 0. I do a similar thing when I add the card to the superview and it fades in fine. But when I call fadeAway, it just disappears immediately. The presentation code is in my controller class. Here is my Card.h and Card.m
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#class Card;
#interface Card : UIView {
int upperOperand;
int lowerOperand;
NSString* theOperator;
int theResult;
}
#property(nonatomic) int upperOperand;
#property(nonatomic) int lowerOperand;
#property(nonatomic, retain) NSString* theOperator;
#property(nonatomic) int theResult;
- (void)fadeAway;
#end
#import "Card.h"
#implementation Card
#synthesize upperOperand;
#synthesize lowerOperand;
#synthesize theOperator;
#synthesize theResult;
- (void)fadeAway {
self.alpha = 1.0f;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:2.0f];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
self.alpha = 0.0f;
[UIView commitAnimations];
[self removeFromSuperview];
}
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
// Initialization code
self.backgroundColor = [UIColor redColor];
self.layer.cornerRadius = 15;
self.alpha = 1.0;
self.layer.borderColor = [[UIColor blueColor] CGColor];
self.layer.borderWidth = 4;
}
return self;
- (void)dealloc {
[super dealloc];
}
#end
Since you're removing self from its superview immediately, I don't think it ever has a chance to perform the animation.
You might want to look into setAnimationDidStopSelector:. There's a discussion on this here: Animation End Callback for CALayer?
Another idea is to delay the removal of the subview. For example,
[self performSelector:#selector(removeFromSuperview)
withObject:nil
afterDelay:2.0f];

how to animate image on shake effect?

I have implemented game application.In which i want to animate some area of images on shake effect.How it possible please give me advice.
Edit:
My excatly query is that:
In my game application there is one image.Now i am selected some area frame of image.now i am shaking iphone then only selected area of frame image must be animate.
Here is a skeleton ... then you can get more detail at the suggested docs. This is real simple-minded but has a randomization and you can instantiate with your own image. I created an image container as a UIViewController and in my main (either your AppDelegate or the RootViewController) you create the instance in viewDidLoad. The methods that have to be overloaded in your AppDelegate, (the code is at the end of the post) so it receives shakes, are:
viewWillAppear
viewDidAppear
viewWillDisappear
viewDidDisappear
canBecomeFirstResponder
becomeFirstResponder
nextResponder
You become a responder in viewWillAppear and you have to enable the device notifications (verified that there is a documented bug) so the motion methods get invoked.
motionBegan:withEvent
motionEnded:withEvent
I like to put an NSLog(#"%s", FUNCTION); statement in all my first-time written methods, that way I can quickly determine if something is missing to get my events, properly initialized, etc. Its just my style.
AnimatedImage.h isA ViewController
#interface AnimatedImage : UIViewController {
UIImageView *image;
UILabel *label;
float cx;
float cy;
float duration;
float repeat;
}
#property (nonatomic, retain) UIImageView *image;
#property (nonatomic, retain) UILabel *label;
-(id) initWithImageName: (NSString*) imageName;
-(IBAction) shake;
AnimatedImage.m
#include <stdlib.h>
#define random() (arc4random() % ((unsigned)RAND_MAX + 1))
#import "AnimatedImage.h"
#implementation AnimatedImage
#synthesize image;
#synthesize label;
-(id) initWithImageName: (NSString*) imageName {
NSLog(#"%s", __FUNCTION__);
image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]];
return self;
}
-(IBAction) shake {
cx = 0.90 + (random() % 10) / 100; // cx = 0.95;
cy = 0.90 + (random() % 10) / 100; // cy = 0.95;
duration = ( 5.0 + random() % 10) / 1000.0;
repeat = (65.0 + random() % 20);
image.transform = CGAffineTransformScale(CGAffineTransformIdentity, cx, cy);
[UIView beginAnimations: #"identifier" context: #"shake"];
[UIView setAnimationDelegate:image.superclass];
[UIView setAnimationDuration: duration]; // 0.008];
[UIView setAnimationRepeatCount: repeat]; // 85.0];
[UIView setAnimationRepeatAutoreverses: YES];
image.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.0, 1.0);
[UIView commitAnimations];
}
-(IBAction) bounce {
image.transform = CGAffineTransformTranslate(image.transform, -20, -6);
[UIView beginAnimations: #"identifier" context: #"bounce"];
[UIView setAnimationDelegate:image.superclass];
[UIView setAnimationDuration: duration];
[UIView setAnimationRepeatCount: repeat];
[UIView setAnimationRepeatAutoreverses: YES];
image.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.0, 1.0);
[UIView commitAnimations];
}
#end
This "root or main" delegate is a UIViewController. I have left of detail to show its simplicity, but still left my 'trace' code that I find essential for first-time debugging. Also, as an aside, I believe you have to overload motionBegan, even if you only need the motionEnded event. I recall that my app did not work and then I added the motionBegan and it started to call motionEnded. It kinda' makes sense that it would be that way, but I don't have any documentation to back it up. A simple experiment after you get it working can confirm or deny my comment.
- (void)viewDidLoad {
[super viewDidLoad];
[super becomeFirstResponder];
.
.
.
NSLog(#"%s", __FUNCTION__);
NSLog(#"%s: I %s first responder! (%#)", __FUNCTION__, [self isFirstResponder] ? "am" : "am not", self);
.
.<created image in this ViewController's NIB using IB>
.
someImage = (UIImageView *) [self.view viewWithTag:TAG_SOMEIMAGE];
aniImage = [[AnimatedImage alloc] init];
aniImage.image = someImage;
}
-(void) viewWillAppear: (BOOL) animated{
NSLog(#"%s", __FUNCTION__);
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver: self
selector: #selector(receivedRotate:)
name: UIDeviceOrientationDidChangeNotification
object: nil];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
NSLog(#"%s", __FUNCTION__);
[super becomeFirstResponder];
assert( [self canPerformAction:#selector(motionEnded:withEvent:) withSender:self] );
}
- (void)viewWillDisappear:(BOOL)animated {
NSLog(#"%s", __FUNCTION__);
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver: self];
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
NSLog(#"%s", __FUNCTION__);
[super resignFirstResponder];
}
- (BOOL)canBecomeFirstResponder {
NSLog(#"%s", __FUNCTION__);
return YES;
}
- (BOOL)becomeFirstResponder {
NSLog(#"%s", __FUNCTION__);
return YES;
}
- (UIResponder *)nextResponder {
NSLog(#"%s", __FUNCTION__);
return [self.view superview];
}
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
NSLog(#"%s", __FUNCTION__);
}
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
NSLog(#"%s", __FUNCTION__);
if( [self isFirstResponder] ) {
[aniImage shake];
}
}
This code does work -- but if I snipped out too much detail, just ask and I will make certain to add enough to help you along. This was a really rewarding task for me and I am excited to share it with someone looking for some help in the same experience.
Have a look at LocateMe example code, one of the first samples in the SDK and use and change the bounce back to centre code.