Reputation: 5302
I have a UIView as a panel for drawing a signature and I've came up with a bit of code to expand and contract the panel when tapped. It seems to work well enough but the code seems really clumsy and I was wondering if there's perhaps a better way to achieve this.
I added a tap gesture recogniser to the view, hooked it up and have this in my .m
:
BOOL clientSigLarge;
- (IBAction)handleSigTap:(id)sender
{
CGRect frame = self.clientSigView.frame;
if (clientSigLarge)
{
frame.size.height -= 400;
frame.size.width -= 350;
frame.origin.x += 350;
frame.origin.y += 400;
self.clientSigView.frame = frame;
clientSigLarge = NO;
}
else
{
frame.size.height += 400;
frame.size.width += 350;
frame.origin.x -= 350;
frame.origin.y -= 400;
self.clientSigView.frame = frame;
clientSigLarge = YES;
}
}
Any tips appreciated.
Upvotes: 1
Views: 975
Reputation: 14118
To make it smoother, use animation block and if your scaling-proportion is fixed (like 2x, 3x, etc.) then use CGAffineTransformScale
[UIView animateWithDuration: 1
delay: 0
options: (UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction)
animations:^{myView.transform = CGAffineTransformScale(CGAffineTransformIdentity, xScaleValue, yScaleVale);}
completion:^(BOOL finished) { }
];
So in if-else condition just change X and Y scale values and use the same block.
Here is a reference link for animations
Hope this is what you are looking for
Upvotes: 1