4 ms·
In RubyMotion, you can do something like: def animate(*args) UIView.begin_animation yield(*args) UIView.commit_animation end ani
by jballanc 15y ago
In RubyMotion, you can do something like:
def animate(*args)
UIView.begin_animation
yield(*args)
UIView.commit_animation
end
animate(myButton, &buttonAnimateBlockFromSomewhereElse)
animate(myView, myOtherView, &genericAnimateBlockFromSomewhereElseWithTwoArgs)
animate do
# Do something locally ignoring args
end
And, yes, you can do the same thing with Obj-C and some creative casts...but it's nicer in RubyMotion! (ymmv)
- jawngee 15y agoYou do it this way: [UIView animateWithDuration:1.0f animations:^{ self.view.alpha=0.0f; }]; Not so hard.
- jballanc 15y agoBut what if I want to have my animations in one object, and my elements to animate in another? Yes, you can have an Obj-C method return a block, but you're going to have to do some nasty casting if you want to be able to call those blocks with an arbitrary number of arguments. (That, or box everything up in an NSArray, which kinda sucks.) I think I'll try and write up a demo app to explain what I mean...
- jawngee 15y agoYes please do because you are making absolutely no sense whatsoever. I think you are over thinking things.
- randomdata 15y agoHe wants to be able to pass any Proc to his method, and any arguments supplied to the method are yielded onto target. A rough Objective-C equivalent would be something like this: void animate(void (^block)(va_list), ...) { va_list args; va_start(args, block); block(args); va_end(args); } void (^first)(va_list) = ^(va_list args) { NSLog(@"%@", va_arg(args, id)); }; void (^second)(va_list) = ^(va_list args) { NSLog(@"%@", va_arg(args, id)); NSLog(@"%@", va_arg(args, id)); }; animate(first, @"Hello World"); animate(second, @"Hello", [[NSNumber alloc] initWithInt:10]); I would like to see the real-world code too. The frameworks in question revolve around Obj-C-isms, so to see something that completely deviates from those patterns will be interesting.