half of the track image is clipped if thumb is smaller than the mask
troelsrichter opened this issue · comments
First of all great work. Best customizable switch I've found and easy to work with.
I have a little problem though. I'm creating a switch where the thumb is a little bit smaller than the mask, but this seems to introduce a problem where half of the track is clipped.
I've fixed the problem by commenting out two lines that calls mask:
updateThumbPositionAnimated:(BOOL)animated
{
CGFloat newThumbXCenter = floorf((self.thumbImageView.frame.size.width / 2) + self.thumbInsetX);
if (_on) {
CGFloat range = floorf(self.frame.size.width - 2 * self.thumbInsetX - self.thumbImageView.frame.size.width);
newThumbXCenter += range;
}
[self thumbImageHighlighted:NO];
if (animated) {
CGFloat distanceOfTravel = fabsf((_on ? 1.0f : 0.0f) - [self valueAtThumbPosition]);
CGFloat animationDuration = kTTSwitchAnimationDuration * distanceOfTravel;
[UIView animateWithDuration:animationDuration animations:^{
[self.thumbImageView setCenter:(CGPoint){ newThumbXCenter, self.thumbImageView.center.y }];
[self.trackImageView setCenter:(CGPoint){ newThumbXCenter, self.trackImageView.center.y }];
} completion:^(BOOL finished) {
//[self mask];
}];
}
else {
[self.thumbImageView setCenter:(CGPoint){ newThumbXCenter, self.thumbImageView.center.y }];
[self.trackImageView setCenter:(CGPoint){ newThumbXCenter, self.trackImageView.center.y }];
//[self mask];
}
}
This fixes the problem and it doesn't seem to brake your demo. I cant figure out why you are masking out the half of the track?
I am trying to reproduce this but not exactly sure how to. Can you provide the code you are using to create the switch. If you could also email me the images you are using that would really help.
My email is penrose [at] gmail [dot] com
I understand now. This functions as designed but I will add a property to turn off masking when fully on/off.