I have this method which lets me translate the position of an object, animating its move in my iPhone app:
-(void)translatePositionForLabel:(UILabel *)label toFrame:(CGRect)newFrame
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
label.frame = newFrame;
[UIView commitAnimations];
}
You can see this works for UILabels, but without having a duplicate of this method (just swapping the object for say UIButton) is there anyway I can adapt this method so I can pass any object with a frame? Rather than needing an individual method for each object type.
Both
UILabelandUIButtonhave a common ancestor inUIView; try passing that in place oflabel(you only appear to modify the label’sframeproperty, which is defined inUIView).