Closed gerchicov-bp closed 9 years ago
Sorry to take so long to reply. I'm not sure what you mean about the demo project. The animation in the demo can be run as many times as you like, just it can't be fired off again while the animation is in-flight. Is there some other behavior you're suggesting for the demo?
When you ask about preventing the same animation from being executed twice, do you mean having some way to check if an RZViewAction
has been started (and/or completed)? If so, this is something I'd consider adding to the API. If this isn't what you mean, could you clarify the question? Thanks!
You have almost understood me. I asked about not simply checking if the same RZViewAction
is already run but about something like the following inside your library:
In .h file:
@interface RZViewAction : NSObject
...
@property (nonatomic, assign) BOOL allowSameSimultaneousAnimations;
@end
In .m file:
@implementation UIView (RZViewActions)
...
+ (void)rz_runAction:(RZViewAction *)action
{
BOOL isSameAnimation = ...; //to check somehow
if (allowSameSimultaneousAnimations || !isSameAnimation)
[self rz_runAction:action withCompletion:nil];
}
@end
And of course by default allowSameSimultaneousAnimations == YES
It looks like you want to be able to prevent the same RZViewAction
from being executed simultaneously with itself. I think the use case for this functionality is extremely limited. I say this because a majority of the time RZViewActions
will be created on the fly and will not be stored. The only way to compare RZViewActions
for equality is pointer comparison because their animation blocks are not comparable. Therefore even if allowSameSimultaneousAnimations == NO
, two RZViewActions
doing the exact same animation could still execute simultaneously if they were different objects.
What about to add something like NSString *actionID
? So usual actions has such id set to nil
and you could compare actions with ids. Note animateWithDuration:
hasn't such id but:
[UIView beginAnimations:@"ToggleViews" context:nil];
RZViewActions won't be using the semi-deprecated begin/commitAnimations
API given that the docs state:
Use of this method is discouraged in iOS 4.0 and later.
You should use the block-based animation methods to specify your animations instead.
The block-based UIView
animation system has no way to specify a key or ID for animations, as you noted. Given this, it would be quite difficult to associate animations with an ID and prevent ones with the same ID from executing simultaneously without managing animation state globally. I think there would have to be a pretty compelling use case to make such a large change.
Ok, if it is difficult then let leave it
We usually check it in the outer code and I saw it in your demo but what about to build in this check into your code? For example, look at your demo again please. You can call
[self.spinner startAnimating];
for infinite times but will be animated only once. And in the same time if you comment/delete this string and the custom animation will start as many times as you click the screen.