I give the following recommendations, they may be good for you.
Note 1, AffineTransform
If the translation is always to the same point and always with the same measure, I'd recommend using CGAffineTransformMakeTranslation(<#CGFloat tx#>, <#CGFloat ty#>)
instead of modifying the view's frame. This method specifies how much x and y points will the view move.
In that way, returning the view to the original position is as simple as doing view.transform = CGAffineTransformIdentity.
Both of these inside their respective animation block of course.
Note 2, Using CGPoint to move the origin
If you just move the origin of the view then the recommendation is to make:
CGRect hiddenFrame = self.view.frame;
hiddenFrame.origin.y -= 736;
self.view.frame = hiddenFrame;
or
CGRect hiddenFrame = self.view.frame;
hiddenFrame.origin.y = -368;
self.view.frame = hiddenFrame;
or
CGRect hiddenFrame = self.view.frame;
hiddenFrame.origin = CGPointMake(0,-368);
self.view.frame = hiddenFrame;
The same for the move back. It's more code but it's more understandable.
Note 3, UIView animation block
You should use the new blocks:
[UIView animateWithDuration: 0.25 animations: ^(void) {
//animation block
}];
There are other blocks with more methods as delay, completion blocks, etc.
Option, Delegate or reference passing
When you create your modal controller, pass the reference of the current controller:
self.tdModal2 = [[TDSemiModalViewController2 alloc]init];
self.tdModal2.delegate = self;
You should declare that property in the TDSemiModalViewController2.h. Either by declaring the @class FooterViewController
to avoid crossed imports; by making a protocol and declaring the property as id<myModalProtocol>
, FooterViewController should then implement the protocol with the method moveBack
; Or just declare the property as id and call [self.delegate performSelector: @selector(moveBack)]
.
Then in the cancel method, simply do:
[self dismissSemiModalViewController:self];
[self.delegate moveBack] //or performSelector.. in the third option case