【问题标题】:change position of imageview with animation用动画改变图像视图的位置
【发布时间】:2011-08-10 08:11:58
【问题描述】:

我想用动画改变 imageview 的位置。它就像抽纸牌一样,它将集中在这里帮助我的任何人。

代码-:

 @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;

/* // 指定的初始化器。覆盖以执行加载视图之前所需的设置。

 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
 self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
 if (self)
 {
    // Custom initialization
 }
 return self;
}

// 实现 viewDidLoad 以在加载视图后进行额外设置,通常从 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];
}

这是我的数据,它可以帮助我解决这个问题..

【问题讨论】:

    标签: iphone animation uiimageview core-animation position


    【解决方案1】:

    试试这样的:

    [URImageView setFrame:CurrentPositionFrame];

    [UIView beginAnimations:@"animateTableView" context:nil];

    [UIView setAnimationDuration:0.4];

    [URImageView setFrame:ToTheNewPositionFrame];

    [UIView 提交动画];


    正如 Till 所指出的,您还可以使用 Center 属性:

    [UIView beginAnimations:@"animateTableView" context:nil];

    [UIView setAnimationDuration:0.4];

    [URImageView setCenter:CGPointMake(nPositionX ,nPositionY)];

    [UIView 提交动画];

    谢谢直到

    【讨论】:

    • 如果您只需要移动,而不是重新分配框架,使用 center 属性。
    • @interface PockerAppViewController : UIViewController { UIButton *btn; UIImageView *卡片; @property(nonatomic,retain) IBOutlet UIButton *btn; @property(nonatomic,retain) IBOutlet UIImageView *cards; -(IBAction)hidebtn:(id)发件人; -(无效)setCards; @end --------------------------------.m 文件------------- ----------------
    • @user652795: 你能不能更新更新你的问题,不能真正清楚地阅读代码。
    • 嘿,谢谢,移动单个对象对我很有帮助,它会正常工作。但我想在数组的多个图像上创建动画。就像有 4 个玩家,我在不同的位置给每个成员抽一张牌。你能告诉我吗?
    【解决方案2】:

    认为这可能会有所帮助 http://www.flashgamehole.com/Tong/play-game/en/

    【讨论】:

      猜你喜欢
      • 2016-04-03
      • 1970-01-01
      • 2016-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-15
      • 2013-02-10
      相关资源
      最近更新 更多