1

I have implemented the drag and drop functionality using

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

In the touchesBegan I check if the according image on the screen was hit, I make a copy of it on the same exact place and start resizing it using the following code :

[UIView animateWithDuration:1.0f
                     animations:^{
                         CGRect oldFrame = copy.frame;
                         copy.frame = CGRectMake(oldFrame.origin.x,oldFrame.origin.y, oldFrame.size.width+60, oldFrame.size.height+60);
                     }
                     completion:^(BOOL finished){
                     }];

The problem that I am getting is that the animations are not actually visible until touchesMoved is triggered. In other words if I press the image and there is no move recorded for more then 1s nothing happens during this time, but if I suddenly move the finger I already see the resized image, but if I start moving in less then 1s I see how the image gets resized in the way while I drag it.

How should I change the code such that the image get's resized even if touchesMoved is not triggered?

Edits:

the only code triggered in touchesMoved is :

CGPoint newPoint = [[touches anyObject] locationInView:self.view];
[copy setCenter:newPoint];
Alexandru Barbarosie
  • 2,952
  • 3
  • 24
  • 46

2 Answers2

0

This seemed to work for me (in an example that wasn't using touches, however).

CGRect oldFrame = copy.frame;
oldFrame = CGRectMake(oldFrame.origin.x,oldFrame.origin.y, oldFrame.size.width+60, oldFrame.size.height+60);
[copy layoutIfNeeded];
[UIView animateWithDuration:1.0f animations:^{
     copy.frame = oldFrame;
}];

The key is to use layoutIfNeeded for animations that don't seem to be animating. If you're using autolayout, this thread might be more useful:

Are NSLayoutConstraints animatable?

Community
  • 1
  • 1
mitrenegade
  • 1,834
  • 18
  • 28
0

My solution was to add a dummy method that is being called at the end of touchesBegan. This removed the problem I was having and the animation was visible before the touchesMoved was triggered.

Alexandru Barbarosie
  • 2,952
  • 3
  • 24
  • 46