domesticcatsoftware / dcroundswitch Goto Github PK
View Code? Open in Web Editor NEWA 'modern' replica of UISwitch.
License: MIT License
A 'modern' replica of UISwitch.
License: MIT License
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.
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:
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!
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
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];
}
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;
}
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?
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.
[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:
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
I swapped out a UISwitch and added DCRoundSwitch to the accessoryView of my cells. The toggle of the switch uses the incremented tag of each switch to keep track of which row the call came from. The target method is being executed multiple times per toggle of each switch...
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!
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?
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
[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]; }
Instruments Version 4.0 (3538) (try to create a switch & remove it, don't use the demo app, as its not releasing...)
change
changes to make kvo work:
[self willChangeValueForKey:@"on"];
on = newOn;
[self didChangeValueForKey:@"on"];
As shown in this video: http://dl.dropbox.com/u/1632081/DCRoundSwitchBug.mov
Reproduction:
You will see that the mask is not being correctly applied while panning the knob.
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?
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?
My swicthes are small and it would be nice if the text could be resized.
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)];
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.