GithubHelp home page GithubHelp logo

dcroundswitch's People

Contributors

0xced avatar domesticcatsoftware avatar lordlobo avatar petec avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dcroundswitch's Issues

kvo doesn't work for "on" property

change

  • (void)setOn:(BOOL)newOn animated:(BOOL)animated ignoreControlEvents:(BOOL)ignoreControlEvents

changes to make kvo work:

[self willChangeValueForKey:@"on"];
on = newOn;
[self didChangeValueForKey:@"on"];

Crash with Arc enabled for tint color

Get a crash in both the demo and my project when using the arc refactored version

CGContextSetFillColorWithColor(context, self.onTintColor.CGColor);

Line 54 in DCRoundSwitchToggleLayer.m

Bad access error.

When using ARC line 57 of DCRoundSwitchKnobLayer.m Crashes

Line 57 (CFArrayRef ColorsArray =...) crashes with ARC enabled. I'm not sure how to work around the issue. I know you have to make some modifications for C structs and ARC, but I don't know enough about C to make the changes. Anyone have a workaround?

CGGradientRef CreateGradientRefWithColors(CGColorSpaceRef colorSpace, CGColorRef startColor, CGColorRef endColor)
{
CGFloat colorStops[2] = {0.0, 1.0};
CGColorRef colors[] = {startColor, endColor};
CFArrayRef colorsArray = CFArrayCreate(NULL, (const void**)colors, sizeof(colors) / sizeof(CGColorRef), &kCFTypeArrayCallBacks);
CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, colorsArray, colorStops);
CFRelease(colorsArray);
return gradient;
}

Weird console output: snarfed from ivar layout: offText = OFF

Everything works perfectly, events are fired correctly, and the control looks awsome.

But for some reason I get A LOT of these messages on the console:

.......
ivar layout: offText = ON
ivar layout: offText = OFF
ivar layout: offText = ON
ivar layout: offText = OFF
......

Has anyone found how to fix this or where it is coming from?

Crash on ln 363 of DCRoundSwitch.m, due to deallocated target

First of, thanks for such a great class!

There's a possibility of a crash when DCRoundSwitch calls sendActionsForControlEvents, if one of the targets of the switch as been deallocated. It's caused by delaying the sendActions... call to after the animations have completed. I assume that this is matching UISwitches behavior, but I don't think UISwitch has this crash. One way to reproduce it is to have a view controller be a DCRoundSwitch target, then flip the switch and hit back as soon as you can afterward, causing the view controller to be deallocated.

Exception:

*** -[SettingsController performSelector:withObject:withObject:]: message sent to deallocated instance 0x7a84020

Code:

[CATransaction setCompletionBlock:^{
    [self removeLayerMask];
    ignoreTap = NO;

    // send the action here so it get's sent at the end of the animations
    if (previousOn != on && !ignoreControlEvents)
        [self sendActionsForControlEvents:UIControlEventValueChanged]; // (Crashes here)
}];

This can be fixed in the dealloc of the targets, by having the target remove itself from the switch, like so:

- (void)dealloc {
    [self.mySwitch removeTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventAllEvents];
}

I'm not sure what the fix should be size I do believe the value changed event for UISwitches gets fired after the animation completes. At the least instructions to prevent this crash should be added to the docs.

DCRoundSwitch In Custom Cell Fires On Table Reload

Hi,

I'm having the same issue mentioned in http://www.scriptscoop.net/t/5baff8171039/uitableview-dcroundswitch-in-custom-cell-fires-on-table-reload.html. As of a solution I found that one of the answers works pretty well, which is in DCRoundSwitch.m file, locate method:

  • (void)setOn:(BOOL)newOn animated:(BOOL)animated ignoreControlEvents:(BOOL)ignoreControlEvents

Deleting below lines;
[[self allTargets] makeObjectsPerformSelector:@selector(retain)];
[[self allTargets] makeObjectsPerformSelector:@selector(release)];

Would be great if the author can update the source. Of note, I'm using this via cocoa pods.

Thank you very much for providing such a cool custom switch!

Various issues

From CocoaControls.com:

Awesome work. I'd love to see a metal gradient knob (rendered in Core Graphics), but I just don't know if that's even possible.

Looking very nice. Is it just me or is the on/off text too far down by 1 pixel?

Crash in ARC project when adding a target after setting .on property

If you add a target immediately after setting the "on" property, there's an EXC_BAD_ACCESS triggered when the switch slide animation completes.

E.g.

toggle.on = someBoolean;
[toggle addTarget:self action:@selector(aSelector:) forControlEvents:UIControlEventValueChanged];

Perhaps something to do with the [[self allTargets] makeObjectsPerformSelector:@selector(retain)]; and
[[self allTargets] makeObjectsPerformSelector:@selector(release)]; in the property setter - i.e. [self allTargets] is empty when the animation begins, but has the new target when the animation completes, causing an over-release?

Continuos jumping state on-off

In my app I prepare the switch state and observe the UIControlEventValueChanged event on it, to change some internal state.
The problem is that I receive the UIControlEventValueChanged event even if I set the state of the switch. With UISwitch object this doesn't happen.

The problem come from the last parameter on the setOn:animated: method in DCRoundSwitch class

- (void)setOn:(BOOL)newOn animated:(BOOL)animated
{
    [self setOn:newOn animated:animated ignoreControlEvents:NO];
}

DCRoundSwitch causes UIAlertViews to lose their elastic animation

Hi, I'm popping up a UIAlertView as the result of a DCRoundSwitch toggle, but this line in DCRoundSwitch.m:

// turn off the animations so the user doesn't see the changing of mask/clipping
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];

is causing the elastic animation of the UIView to fail, so UIAlertViews instantly appear.

Code is crashing when trying to call the selector

[self.switch1 addTarget:self action:@selector(switch1Toggled:) forControlEvents:UIControlEventValueChanged];

When this line is enabled in the code and you click on the switch it crashes in the simulator to assembly code, once the debugger dropped a message that an invalid selector was being called.

This was the code for the selector:

  • (void)switch1Toggled:(id)sender
    {
    [switch2 setOn:!switch2.isOn animated:YES];
    }

I am using Xcode 4.4.1 with iOS 5.1 simulator.

Here is a dump log:
2012-08-17 19:37:41.565 DCRoundSwitchDemo[1654:c07] -[__NSCFString switch1Toggled:]: unrecognized selector sent to instance 0x6a8f580
2012-08-17 19:37:41.568 DCRoundSwitchDemo[1654:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString switch1Toggled:]: unrecognized selector sent to instance 0x6a8f580'
*** First throw call stack:
(0x1379022 0x106ecd6 0x137acbd 0x12dfed0 0x12dfcb2 0x137ae99 0x1d414e 0x1d40e6 0x27aade 0x27afa7 0x27ab13 0x754e 0x2128330 0x212a509 0x12b0803 0x12afd84 0x12afc9b 0x21847d8 0x218488a 0x1d1626 0x2bdd 0x2b55 0x1)
terminate called throwing an exception(lldb)

I am getting this if two buttons are pointing to the same selector, or it appears by simply adding a new button with a new selector....All this work is in the sample app that comes with the kit.

Thanks,
Tony

UIView Animations For Value Changed

[UIView animateWithDuration...] methods don't work when called in response to the switch's value being changed. This can be fixed very easily by replacing these lines in setOn:animated:ignoreControlEvents:

if (previousOn != on && !ignoreControlEvents) [self sendActionsForControlEvents:UIControlEventValueChanged];

with:

if (previousOn != on && !ignoreControlEvents) { [CATransaction begin]; [CATransaction setDisableActions:NO]; [self sendActionsForControlEvents:UIControlEventValueChanged]; [CATransaction commit]; }

DCRoundSwitch blocks animation in UITableView

try to add the switch as a subview to the contentview of a tableviewcell, now the tableview's animations does not work anymore, i tried both - insertRowsAtIndexPaths:withRowAnimation: and -deleteRowsAtIndexPaths:withRowAnimation:

can you confirm this?

Question About Converting to ARC

I'm not sure how to convert the following line to ARC compatible code, and googled a bit and could not come up with the answer. I changed it to nilSymbol and seems to work but wondering if that is correct.

Original code:

[[self allTargets] makeObjectsPerformSelector:@selector(retain)];

Updated code:
[[self allTargets] makeObjectsPerformSelector:@selector(nilSymbol)];

Switch In Custom Cell Fires On Table Reload

Hi,

I have a UITableView containing four rows. Each row has a custom cell with a DCRoundSwitch. The value-changed event is linked in IB to a switchChanged method. Each time a new cell with a switch is needed in cellForRowAtIndexPath I assign the new cell's switch to an ivar so I can control it programmatically like this:

       self.categorySwitch = ((FilterViewCell *)cell).sectionSwitch; 

The problem:
After I change a switch the first time it works perfectly, triggering the switchChanged method. Thereafter, every time a new cell is needed or the table is reloaded, it fires off the switchedChanged method without touching the switch. I've tried the removing all targets at the end of the switchChanged method like so but it still didn't work:

       [theSwitch removeTarget:nil action:NULL forControlEvents:UIControlEventAllEvents];

This works perfectly using UISwitch.

Any suggestions? DCRoundSwitch appears to be an excellent alternative and I would like to use it.

Thanks

Please add semantic version tags.

I’ve recently added DCRoundSwitch to the CocoaPods package manager repo.

CocoaPods is a tool for managing dependencies for OSX and iOS Xcode projects and provides a central repository for iOS/OSX libraries. This makes adding libraries to a project and updating them extremely easy and it will help users to resolve dependencies of the libraries they use.

However, DCRoundSwitch doesn't have any version tags. I’ve added the current HEAD as version 0.0.1, but a version tag will make dependency resolution much easier.

Semantic version tags (instead of plain commit hashes/revisions) allow for resolution of cross-dependencies.

In case you didn’t know this yet; you can tag the current HEAD as, for instance, version 1.0.0, like so:

$ git tag -a 1.0.0 -m "Tag release 1.0.0"
$ git push --tags

Thanks!

Animation Bug

If you click then drag the toggle layer will display over the other layers.

Steps,

Click a switch,
then quickly drag the switch.
You should see the toggle layer overlay the other layers

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.