2014-04-11 106 views
0

我想制作像facebook chat这样的动画:聊天头像。我创建了一个图标。它运行良好,非常顺利。我创建了更多图标。他们也工作。但不一致facebook。是否有任何想法或参考实现功能移动?像facebook聊天一样移动图像

喜欢这部影片: Chat heads

+0

什么是特征移动? – square

+0

试试这个从github的样本.. https://github.com/Tech-Dev-Mobile/IOS-Message-Chat – svmrajesh

+0

@square:我的意思是聊天头。我编辑 – TienLe

回答

2

尝试,这可能是帮助全..但它已经做了的UIButton ..

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[button setTitle:@"Drag me!" forState:UIControlStateNormal]; 

// add drag listener 
[button addTarget:self action:@selector(wasDragged:withEvent:) 
forControlEvents:UIControlEventTouchDragInside]; 

// center and size 
button.frame = CGRectMake((self.view.bounds.size.width - 100)/2.0, 
          (self.view.bounds.size.height - 50)/2.0, 
          100, 50); 

// add it, centered 

[self.view addSubview:button]; 


- (void)wasDragged:(UIButton *)button withEvent:(UIEvent *)event 
{ 
    // get the touch 
UITouch *touch = [[event touchesForView:button] anyObject]; 

// get delta 
CGPoint previousLocation = [touch previousLocationInView:button]; 
CGPoint location = [touch locationInView:button]; 
CGFloat delta_x = location.x - previousLocation.x; 
CGFloat delta_y = location.y - previousLocation.y; 

// move button 
button.center = CGPointMake(button.center.x + delta_x, 
          button.center.y + delta_y); 
} 

我得到这个从这里..for更多信息,你可以找到这里.. Draggable UIButton makes in iPhone & iPad

+0

其工作正常..应该接受这... –