Giter Club home page Giter Club logo

ibanimatable's Issues

Linear animations

Except for Spring animations, sometimes, we need linear animations.

Plugin for prototyping only

Some feature as a plugin will only apply to prototyping in IB. Maybe useful for populating random data like names.

Replace String with enum for the properties are not using in IB

Because @IBInspectable in Interface Builder only support certain types. eg. CGFloat, UIColor, String and Int. But can not support enum inherited from String. eg. enum AnimationType: String.

@lexrus came up a great idea to use enum in programming API and use String in IB.

#if TARGET_INTERFACE_BUILDER
  /**
    String value of predefined Animation Type, all supported types are in `AnimationType` enum
  */
  var animationType: String? { get set }
#else
  /**
   Predefined Animation Type, all supported types are in `AnimationType` enum
   */
  var animationType: AnimationType? { get set }
  var animationTypeRaw: String? { get set }
#endif

Then when the App runs on simulator (not in IB), the compiler actually uses non TARGET_INTERFACE_BUILDER. We have to convert the String value in Storyboard to AnimationType. Method Swizzling on NSKeyedUnarchiver is one way to do that.

I have tried to use Swift protocol extension.

// Use Method Swizzling to convert `String` to emun when loading runtime attributes from Storybaord.
// http://nshipster.com/swift-objc-runtime/
public extension NSKeyedUnarchiver {
  public override class func initialize() {
    struct Static {
      static var token: dispatch_once_t = 0
    }

    // make sure this isn't a subclass
    if self !== NSKeyedUnarchiver.self {
      return
    }

    dispatch_once(&Static.token) {
      let originalSelector = Selector("setValue:forUndefinedKey:")
      let swizzledSelector = Selector("iba_setValue:forUndefinedKey:")

      let originalMethod = class_getInstanceMethod(self, originalSelector)
      let swizzledMethod = class_getInstanceMethod(self, swizzledSelector)

      let didAddMethod = class_addMethod(self, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod))

      if didAddMethod {
        class_replaceMethod(self, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod))
      } else {
        method_exchangeImplementations(originalMethod, swizzledMethod)
      }
    }
  }

  // MARK: - Method Swizzling
  func iba_setValue(value: AnyObject?, forUndefinedKey key: String) {
    if (key == "animationType") {
      setValue(value, forKey: "animationTypeRaw")
    }
  }
}

But initialize never gets called.

Then I tried to do it in didFinishLaunchingWithOptions

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.

    let originalSelector = Selector("setValue:forUndefinedKey:")
    let swizzledSelector = Selector("iba_setValue:forUndefinedKey:")

    let originalMethod = class_getInstanceMethod(NSKeyedUnarchiver.self, originalSelector)
    let swizzledMethod = class_getInstanceMethod(NSKeyedUnarchiver.self, swizzledSelector)

    let didAddMethod = class_addMethod(NSKeyedUnarchiver.self, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod))

    if didAddMethod {
      class_replaceMethod(NSKeyedUnarchiver.self, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod))
    } else {
      method_exchangeImplementations(originalMethod, swizzledMethod)
    }

    return true
  }

but iba_setValue never gets called.

Then back to @lexrus 's solution to do the Method Swizzling in Objective C.

@implementation NSKeyedUnarchiver (IBAnimatable)

- (void)iba_setValue:(id)value forUndefinedKey:(NSString *)key {
  if ([key isEqualToString:@"animationType"]) {
    [self setValue:value forKey:@"animationTypeRaw"];
  }
}

+ (void) load
{
  static dispatch_once_t onceToken;
  dispatch_once(&onceToken, ^{
    SEL originalMethod = @selector( setValue:forUndefinedKey: );
    SEL swizzledMethod = @selector( iba_setValue:forUndefinedKey: );
    method_exchangeImplementations(
                                   class_getInstanceMethod( self, originalMethod ),
                                   class_getInstanceMethod( self, swizzledMethod )
                                   );
  });
}
@end

It is working now. And the storyboard is OK.

But once I add NSKeyedUnarchiver+IBAnimatable.m file to IBAnimatable framework target. Then the iba_setValue (in NSKeyedUnarchiver+IBAnimatable.m) will not get called anymore.

Here is the changes
4a5e081...feature/support-enum-for-non-ib-api

RingDesignable

Can design something like Apple Watch health progress ring.

Method slideOut won't slide out everytime

Following the code, the slideOut methods are always 300 * force, but if we are running this example on an iPad with a force to 1, it will never get the outside screen.

Is there a reason to have hardcoding that constant?

More MaskDesignable

Currently, MaskDesignable only supports Circle, can support more mask like Triangle and Star.

Cannot run included playground

Hello Jake,

A very nice framework you created !!!

Playground execution failed: /var/folders/9y/w9x0q7y56s78qtsn8knw_ns80000gp/T/./lldb/1191/playground15.swift:5:8: error: no such module 'IBAnimatable'
import IBAnimatable

Any suggestions (Xcode 7.2) ?
Thanks
Frank

Exit animation

When working with IBAnimatable, I am thinking of whether I can add an Exit animation when the controller is being dismissed. Actually with this library in place, I have an ambition to design all my apps following animations, effects demonstrated in Presentation softwares such as MS Powerpoint, Apple Keynote.

Chain-able animations

Better syntax for chaining animations.

Just an idea

Animation(view).pop(repeatCount: 2).then.shake(repeatCount:1).and.rotate(.cw, repeatCount:2)

Improving github workflow

It would be great to improve the github workflow:

  • A better usage of labels to differentiate the issues, at least the basic ones if we don't create custom labels
  • Using milestones to determinate which features should be implemented in the next version
  • Something more?

Make this will definitely helps us to priorities and ease the development process.

Any thought?

Design transition animations in Interface Builder

Not only system built-in transitions, more custom transitions support.

  • AnimatableNavigationController to support custom transition animations for Push and Pop
  • AnimatableViewController to support custom transition animations for Present and Dismiss
  • AnimatableTableViewController to support custom transition animations for Present and Dismiss
  • Present***Segue to support custom transition animations for Present and Dismiss
  • ***InteractiveAnimator to support gesture to Pop or Dismiss VC. e.g. Pan, ScreenEdgePan and Pinch.
  • More custom animations.

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.