移动图像像Facebook聊天

时间:2014-04-11 04:51:10

标签: ios objective-c facebook animation core-animation

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

喜欢这个视频: Chat heads

1 个答案:

答案 0 :(得分: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);
 }

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