Question

I really need some help, since iOS 7 I have had nothing but trouble with UISwitch.

The Problem

After moving the view up when the keyboard is displayed and restoring it to original position, I then turn any UISwitch on/off it will work OK, however it will "Bounce Down" during the animation. this only seems to happen to UISwitch's that have the .thumbTintColor attribute. by that I mean self.borders.thumbTintColor = [UIColor redColor]; when the switch is off and self.borders.thumbTintColor = [UIColor greenColor]; when switch is on.

For clarity everything works well until the moving of the view (I can't not do this as you are not able to see the text field).

I have searched everywhere (including the class reference) and I haven't found anything helpful, or anyone else with this problem.

UPDATE

I have tried setting the UISwitch thumTintColor various ways, everything works fine until I move the view up to compensate for the Keyboard. if I drag the switch either on my iPad or via simulator on and off slowly the "bounce down" occurs halfway and when the color changes from green to red or red to green depending on state, I think this is an actual IOS7 UISwitch Bug. I really do not want to use a third part switch plug in on my app, so not sure what to do now, one would of thought that changing the tint color on the thumb would not have been such a huge problem.

I have tried turning off the animation from on to off - off to on makes no difference.

I have created a new UISwitch via code not IB and the same problem exists.

created a new test app with only a switch and text box to test and the same thing occurs.

Questions

1) My thoughts are this is a genuine bug. How do i log it with apple (never done it before) so if someone can point me to the correct place i would be grateful.

2) I am now thinking of using Buttons as switches, but feel that is not the way to go, are there any practical reasons not to do so i.e problems submitting the app to the App store etc?

Was it helpful?

Solution 2

Answer 1: Logging a bug with apple can be done via the iOS Dev center (There's a link on the bottom of the page). You can also ask for technical support. Click on the "Developer Support Center" button, then go to "Technical Support (TSI)" (Please note you only have a limited amount that you're allowed to use per year, before you have to buy more).

Answer 2: I think that having two buttons would be a very bad User Interface decision. Apple may reject it because of that (but you never know). I would get the bug report in, and go from there.

Good Luck!

OTHER TIPS

I had the similar issue and found a solution. It's a bit hacky but it does the job. Just need to add a small delay between setting isOn property to On/Off and changing the color of the thumb.

switch.isOn = true
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
  self.switch.thumbTintColor = .white
}

I found interesting solution may be it helps.

    NSArray *array = [self.mySwitch subviewsWithClass:[UIImageView class]];
    for (UIImageView *imageView in array) {
        imageView.image = [UIImage imageNamed:@"Untitled-1.png"];
    }

Hear I used method from UIView category

- (NSArray*)subviewsWithClass:(Class)class
{
    NSMutableArray *array = [NSMutableArray array];
    if ([self isKindOfClass:class]) {
        [array addObject:self];
    }
    for (UIView *subview in self.subviews) {
        [array addObjectsFromArray:[subview subviewsWithClass:class]];
    }
    return array;
}

Image size is {57, 43.5}. Circle radius is 15(with shadow)

I understand that it is not very good way to solve. But if you really need it helps.

enter image description here

enter image description here

Play with images little bit =)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top