static const CGFloat button_offset_ = 20.f;
-( void )moveUpAnimation
{
[ UIView beginAnimations: nil context: nil ];
CGFloat new_y_ = self.animatedButton.frame.origin.y
- ( self.view.frame.size.height - button_offset_ * 2 )
+ self.animatedButton.frame.size.height;
self.animatedButton.frame = CGRectMake( self.animatedButton.frame.origin.x
, new_y_
, self.animatedButton.frame.size.width
, self.animatedButton.frame.size.height );
[ UIView commitAnimations ];
}
* This source code was highlighted with Source Code Highlighter .
-(IBAction)animateButtonAction:( id )sender_
{
[ self moveUpAnimation ];
[ self moveRightAnimation ];
[ self moveDownAnimation ];
[ self moveLeftAnimation ];
}
* This source code was highlighted with Source Code Highlighter .
// ()
@ interface JFFNextAnimation : NSObject
@property ( nonatomic, retain ) UIViewAnimationsExampleViewController* controller;
@property ( nonatomic, assign ) SEL nextAnimationSelector;
@end
-( void )moveUpAnimation
{
JFFNextAnimation* next_animation_ = [ JFFNextAnimation new ];
//
next_animation_.controller = self;
next_animation_.nextAnimationSelector = @selector( moveRightAnimation );
//
[ UIView beginAnimations: nil context: next_animation_ ];
CGFloat new_y_ = self.animatedButton.frame.origin.y
- ( self.view.frame.size.height - button_offset_ * 2 )
+ self.animatedButton.frame.size.height;
self.animatedButton.frame = CGRectMake( self.animatedButton.frame.origin.x
, new_y_
, self.animatedButton.frame.size.width
, self.animatedButton.frame.size.height );
//
[ UIView setAnimationDelegate: self ];
[ UIView commitAnimations ];
}
// moveDownAnimation, moveRightAnimation moveLeftAnimation
-( void )animationDidStop:( NSString* )animation_id_
finished:( NSNumber* )finished_
context:( void * )context_
{
//
JFFNextAnimation* context_object_ = context_;
[ context_object_.controller performSelector: context_object_.nextAnimationSelector ];
[ context_object_ release ];
}
-(IBAction)animateButtonAction:( id )sender_
{
//
[ self moveUpAnimation ];
}
* This source code was highlighted with Source Code Highlighter .
@ interface JFFNextAnimation : NSObject
@property ( nonatomic, retain ) UIViewAnimationsExampleViewController* controller;
// ,
@property ( nonatomic, retain ) NSMutableArray* nextAnimations;
@end
* This source code was highlighted with Source Code Highlighter .
// ,
//
-( void )moveUpAnimationWithNextAnimation:( JFFNextAnimation* )next_animation_
{
[ UIView beginAnimations: nil context: next_animation_ ];
CGFloat new_y_ = self.animatedButton.frame.origin.y
- ( self.view.frame.size.height - button_offset_ * 2 )
+ self.animatedButton.frame.size.height;
self.animatedButton.frame = CGRectMake( self.animatedButton.frame.origin.x
, new_y_
, self.animatedButton.frame.size.width
, self.animatedButton.frame.size.height );
[ UIView setAnimationDelegate: self ];
[ UIView commitAnimations ];
}
// moveDownAnimation, moveRightAnimation moveLeftAnimation
* This source code was highlighted with Source Code Highlighter .
-( void )animationDidStop:( NSString* )animation_id_
finished:( NSNumber* )finished_
context:( void * )context_
{
// -
if ( !context_ )
return ;
JFFNextAnimation* context_object_ = context_;
//
NSString* next_animation_string_ = [ context_object_.nextAnimations objectAtIndex: 0 ];
next_animation_string_ = [ [ next_animation_string_ retain ] autorelease ];
//
[ context_object_.nextAnimations removeObjectAtIndex: 0 ];
SEL next_animation_sel_ = NSSelectorFromString( next_animation_string_ );
if ( [ context_object_.nextAnimations count ] == 0 )
{
//
//
[ context_object_.controller performSelector: next_animation_sel_
withObject: nil ];
//
[ context_object_ release ];
}
else
{
//
[ context_object_.controller performSelector: next_animation_sel_
withObject: context_object_ ];
}
}
* This source code was highlighted with Source Code Highlighter .
-(IBAction)animateButtonAction:( id )sender_
{
JFFNextAnimation* next_animation_ = [ JFFNextAnimation new ];
next_animation_.controller = self;
//
next_animation_.nextAnimations = [ NSMutableArray arrayWithObjects:
@"moveUpAnimationWithNextAnimation:"
, @"moveLeftAnimationWithNextAnimation:"
, @"moveDownAnimationWithNextAnimation:"
, nil ];
//
[ self moveRightAnimationWithNextAnimation: next_animation_ ];
}
* This source code was highlighted with Source Code Highlighter .
-(JFFSimpleBlock)moveUpAnimationBlock
{
return [ [ ^
{
CGFloat new_y_ = self.animatedButton.frame.origin.y
- ( self.view.frame.size.height - button_offset_ * 2 )
+ self.animatedButton.frame.size.height;
self.animatedButton.frame = CGRectMake( self.animatedButton.frame.origin.x
, new_y_
, self.animatedButton.frame.size.width
, self.animatedButton.frame.size.height );
} copy ] autorelease ];
}
* This source code was highlighted with Source Code Highlighter .
//
//
-(JFFSimpleBlock)animationBlockWithAnimations:( JFFSimpleBlock )animations_
completion:( JFFSimpleBlock )completion_
{
// ,
//
completion_ = [ [ completion_ copy ] autorelease ];
return [ [ ^
{
[ UIView animateWithDuration: 0.2
animations: animations_
completion: ^( BOOL finished_ )
{
if ( completion_ )
completion_();
} ];
} copy ] autorelease ];
}
* This source code was highlighted with Source Code Highlighter .
-(IBAction)animateButtonAction:( id )sender_
{
// , ,
JFFSimpleBlock move_left_animation_block_ = [ self moveLeftAnimationBlock ];
//completion: - ,
move_left_animation_block_ = [ self animationBlockWithAnimations: move_left_animation_block_
completion: nil ];
JFFSimpleBlock move_down_animation_block_ = [ self moveDownAnimationBlock ];
//completion: - - "move left"
move_down_animation_block_ = [ self animationBlockWithAnimations: move_down_animation_block_
completion: move_left_animation_block_ ];
JFFSimpleBlock move_right_animation_block_ = [ self moveRightAnimationBlock ];
//completion: - - "move down"
move_right_animation_block_ = [ self animationBlockWithAnimations: move_right_animation_block_
completion: move_down_animation_block_ ];
//
JFFSimpleBlock move_up_animation_block_ = [ self moveUpAnimationBlock ];
//completion: - - "move right"
move_up_animation_block_ = [ self animationBlockWithAnimations: [ self moveUpAnimationBlock ]
completion: move_right_animation_block_ ];
//
move_up_animation_block_();
}
* This source code was highlighted with Source Code Highlighter .
-(JFFAsyncOperation)animationBlockWithAnimations:( JFFSimpleBlock )animations_
{
return [ [ ^( JFFAsyncOperationProgressHandler progress_callback_
, JFFCancelHandler cancel_callback_
, JFFDidFinishAsyncOperationHandler done_callback_ )
{
done_callback_ = [ [ done_callback_ copy ] autorelease ];
[ UIView animateWithDuration: 0.2
animations: animations_
completion: ^( BOOL finished_ )
{
if ( done_callback_ )
done_callback_( [ NSNull null ], nil );
} ];
//
JFFCancelAsyncOpration cancel_block_ = ^{ /*do nothing*/ };
return [ [ cancel_block_ copy ] autorelease ];
} copy ] autorelease ];
}
* This source code was highlighted with Source Code Highlighter .
-(IBAction)animateButtonAction:( id )sender_
{
JFFSimpleBlock move_right_animation_block_ = [ self moveRightAnimationBlock ];
JFFAsyncOperation move_right_async_block_ = [ self animationBlockWithAnimations: move_right_animation_block_ ];
JFFSimpleBlock move_up_animation_block_ = [ self moveUpAnimationBlock ];
JFFAsyncOperation move_up_async_block_ = [ self animationBlockWithAnimations: move_up_animation_block_ ];
JFFSimpleBlock move_left_animation_block_ = [ self moveLeftAnimationBlock ];
JFFAsyncOperation move_left_async_block_ = [ self animationBlockWithAnimations: move_left_animation_block_ ];
JFFSimpleBlock move_down_animation_block_ = [ self moveDownAnimationBlock ];
JFFAsyncOperation move_down_async_block_ = [ self animationBlockWithAnimations: move_down_animation_block_ ];
//
// - sequenceOfAsyncOperations
JFFAsyncOperation result_animation_block_ = sequenceOfAsyncOperations(
move_right_async_block_
, move_up_async_block_
, move_left_async_block_
, move_down_async_block_
, nil );
// ,
result_animation_block_( nil, nil, nil );
}
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/121958/
All Articles