I subclassed a UIImageView. When it is double tapped, it will enlarge itself by 40%. I also have a UILabel that i place in the custom UIImageView and would like it to enlarge by 40%.
i can't seem to get it to animate correctly.
-(void)enlargeImage
{
CGPoint pointCenter = self.center;
CGPoint labelCenter = self.displayNameLabel.center;
[UIView animateWithDuration:1
delay:0
options:(UIViewAnimationOptionAllowUserInteraction)
animations:^{
self.frame = CGRectMake(self.frame.origin.x,
self.frame.origin.y,
self.frame.size.width * (1 + self.sizeMultiplier),
self.frame.size.height * (1 + self.sizeMultiplier));
// Commented out after setting the autoresizeMask on the label
/*
self.displayNameLabel.frame = CGRectMake(self.displayNameLabel.frame.origin.x,
self.displayNameLabel.frame.origin.y,
self.displayNameLabel.frame.size.width * (1 + self.sizeMultiplier),
self.displayNameLabel.frame.size.height * (1 + self.sizeMultiplier));
*/
self.layer.shadowOpacity = 1;
}
completion:^(BOOL finished)
{
[self callDelegateSelect];
}];
self.center = pointCenter;
//self.displayNameLabel.center = labelCenter;
//self.displayNameLabel.center = CGPointMake((self.frame.size.width / 2), (self.frame.size.height / 2));
self.isSelected = TRUE;
}
-(void)shrinkImageWithZoomScale:(float)zoomScale
{
CGPoint pointCenter = self.center;
CGPoint labelCenter = self.displayNameLabel.center;
[UIView animateWithDuration:1
delay:0
options:(UIViewAnimationOptionAllowUserInteraction)
animations:^{
self.frame = CGRectMake(self.frame.origin.x,
self.frame.origin.y,
(self.originalHeight / zoomScale),
(self.originalHeight / zoomScale));
// Commented out after setting the autoresizeMask on the label
/*
self.displayNameLabel.frame = CGRectMake(self.displayNameLabel.frame.origin.x,
self.displayNameLabel.frame.origin.y,
((self.originalLableHeight) / zoomScale),
((self.originalLableHeight) / zoomScale));
*/
self.layer.shadowOpacity = 0;
}
completion:^(BOOL finished)
{
[self callDelegateDeselect];
}];
self.center = pointCenter;
//self.displayNameLabel.center = labelCenter;
//self.displayNameLabel.center = CGPointMake((self.frame.size.width / 2), (self.frame.size.height / 2));
self.isSelected = FALSE;
}
the custom UIImageView animates exactly how i want it too, but the UILabel misbehaves.
unselected (UILabel's background is set to orange):
selected:
i'm guessing since the UIImageView's point reference is changing, its messing up the points i'm telling the UILabel to be?
EDIT:
the custom UIImageView's:
self.autoresizesSubviews = TRUE;
the subview UILabel:
self.displayNameLabel.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
this solves the sizing issue, but it does not grow from the center; when growing, it shifts right and animates left to the center. when shrinking, it shifts left and animates right to the center. I also commented out setting the label's frame in the animation code.