0

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..

2 Answers 2

1

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.

4
  • If all you need is movement, instead of reassigning the frame, use the center property.
    – Till
    Apr 21, 2011 at 13:58
  • @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 --------------------------------.m file-----------------------------
    – Anjan
    Apr 21, 2011 at 14:17
  • @user652795: can you please update update your Question instead, can't really read the code clearly. Apr 21, 2011 at 14:21
  • hey thank's it will really helpful to me to move single object and it will properly working. but i want to create animation on multiple image of array. just like there are 4 players and i draw an card to each memeber so at different position. can you please tell me about it.
    – Anjan
    Apr 23, 2011 at 7:42
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.