Skip to content

Instantly share code, notes, and snippets.

View boherna's full-sized avatar

Bohdan Hernandez Navia boherna

View GitHub Profile
@boherna
boherna / gist:76edbed674e0a20a57dd
Last active June 17, 2018 13:08
Spin animation of indefinite duration (not INFINITE). It can be stopped at an even quarter turn if needed. Also, the acceleration ramps up during the first 90 degrees, and decelerates during the last 90 degrees (after a stop has been requested).
// an ivar for your class:
BOOL animating;
- (void)spinWithOptions:(UIViewAnimationOptions)options
{
// this spin completes 360 degrees every 2 seconds
[UIView animateWithDuration: 0.5f
delay: 0.0f
options: options
animations: ^{
@boherna
boherna / gist:1dcab4f104d3cc647383
Created December 4, 2014 15:08
Remove text from the < Back button.
// To be placed in the parent viewcontroller which will push the viewcontroller where the back button should be blank
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
@boherna
boherna / gist:33002692c103c3a1ab58
Last active June 17, 2018 13:05
To find the window containing the keyboard.
- (UIWindow *)findKeyboardWindow
{
UIWindow *keyboardWindow = nil;
for (UIWindow *window in [[UIApplication sharedApplication] windows])
{
if ([NSStringFromClass([window class]) isEqualToString:@"UITextEffectsWindow"])
{
keyboardWindow = window;
break;
}
@boherna
boherna / gist:226a52bb539796da8302
Last active June 17, 2018 13:07
To animate (fade) text change in UILabel
CATransition *animation = [CATransition animation];
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.type = kCATransitionFade;
animation.duration = 0.75;
[aLabel.layer addAnimation:animation forKey:@"kCATransitionFade"];
// The current text will fade to new text.
aLabel.text = @"new text";
@boherna
boherna / gist:9e3d223be4c8f2491a87
Last active November 1, 2023 23:57
To animate (fade) text change in UILabel (SWIFT)
The proper way to fade a UILabel (or any UIView for that matter) is to use a Core Animation Transition. This will not flicker, nor will it fade to black if the content is unchanged.
A portable and clean solution is to use a Extension in Swift (invoke prior changing visible elements)
// Usage: insert view.fadeTransition right before changing content
extension UIView {
func fadeTransition(duration:CFTimeInterval) {
let animation:CATransition = CATransition()
animation.timingFunction = CAMediaTimingFunction(name:
kCAMediaTimingFunctionEaseInEaseOut)
@boherna
boherna / gist:536f13431d2b9e7b03ef
Last active August 13, 2024 17:02
Solve cocoapods, ruby, gems, brew conflicts...
Open Terminal and enter:
gem uninstall cocoapods (Select 'All versions' option.)
sudo rvm implode (Confirm with 'yes' when prompted.)
sudo brew doctor
sudo brew update
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
\curl -L https://get.rvm.io | bash -s stable --ruby
rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup (Maybe not needed)
sudo gem update --system
@boherna
boherna / UIButton+Copy.swift
Created June 17, 2018 12:57
How to copy a UIButton using Swift
public extension UIButton {
func copy<T: UIButton>(withControlEvents controlEvents: [UIControlEvents]) -> T? {
let data = NSKeyedArchiver.archivedData(withRootObject: self)
guard let copy = NSKeyedUnarchiver.unarchiveObject(with: data) as? T else { return nil }
if let font = titleLabel?.font {
copy.titleLabel?.font = font
}
if let lineBreakMode = titleLabel?.lineBreakMode {
copy.titleLabel?.lineBreakMode = lineBreakMode