Reputation: 508
i have searched a lot here but can't seem to find the answer to my question...
I have a class called SubView, this class has a simple ability, it can show up or dissapear animated
it does it like this:
-(void)showAnimated:(BOOL)animated {
self.active = YES;
//Make topmost
[self.parentView bringSubviewToFront:self];
if (animated) {
[UIView animateWithDuration:0.5
delay:0.0f
options:UIViewAnimationCurveEaseInOut | UIViewAnimationOptionBeginFromCurrentState
animations:^{
self.frame = self.originalFrame;
if (self.panningBlock) {
self.panningBlock(self.contentView.frame);
}
}
completion:^(BOOL finished){
}];
}
else {
self.frame = self.originalFrame;
if (self.panningBlock) {
self.panningBlock(self.contentView.frame);
}
}
Where self.originalFrame has stored the original value of the position of the View, the hide portion if really similar
-(void)hideAnimated:(BOOL)animated {
self.active = NO;
//Store the frame
CGRect _frame = self.frame;
//Set the view starting point
switch (self.showingLocation) {
case SubViewShowingLocationRight:
_frame.origin = CGPointMake(_frame.size.width, _frame.origin.y);
break;
case SubViewShowingLocationBottom:
_frame.origin = CGPointMake(_frame.origin.x, _frame.size.height);
break;
case SubViewShowingLocationLeft:
_frame.origin = CGPointMake(-_frame.size.width, _frame.origin.y);
break;
default:
break;
}
if (animated) {
[UIView animateWithDuration:0.5
delay:0.0f
options:UIViewAnimationCurveEaseInOut | UIViewAnimationOptionBeginFromCurrentState
animations:^{
self.frame = _frame;
if (self.panningBlock) {
self.panningBlock(self.contentView.frame);
}
}
completion:^(BOOL finished){
}];
}
else {
self.frame = _frame;
if (self.panningBlock) {
self.panningBlock(self.frame);
}
}
[self.delegate didDismissSubView:self];
}
//// So the animation occurs at self.frame = _frame and self.frame = self.originalFrame
also i have self.panningBlock, that is a block that the parent view can give (it works so it can adjust himself to the frame change of the subview.. i.e. sub view has a picker, and it appears from bottom, i need to adjust the table view so it isn't obscured by the picker)
An Example of what i do is
__weak MapViewController * weakSelf = self;
[weakSelf.placesView setPanningBlock:^(CGRect _frame){
if (weakSelf.placesView.isActive) {
CGRect mapFrame = weakSelf.mapView.frame;
mapFrame.origin.x = _frame.origin.x + _frame.size.width;
weakSelf.mapView.frame = mapFrame;
}
else {
CGRect mapFrame = weakSelf.mapView.frame;
mapFrame.origin.x = 0;
weakSelf.mapView.frame = mapFrame;
}
}];
Here the parent view moves right if the subview appear to give a push like animation
That's all the code needed to understand (this is my first question, so forgive any rambling here)
The point is that the animations won't occur at the same time, what happens is that the view that is entering enters a little more slow than the parent view they don't stick together, and i really don't know what to do...
BTW: they do stick together the first time the animation occurs, but no more there after..
any suggestions?
EDIT i now give some images as to explain what happens
Upvotes: 0
Views: 758
Reputation: 508
I put this as the answer wasn't reached actually...
The issue here was with.. the total size of the views...
the MAPVIEW sized 100% whilst the tableview sized 80%... i was putting them on the same animation... so they will move differently because they have to cover 1.0 second or so of animation for the entire movement...
This problem is fixed by doing an EXPLICIT ANIMATION... there are some libraries out there... i used one that destroyed my project... so i ended up ditching it... and took a more... patch solution... putting the background color so it masks the movement...
The solution to this problem is using an explicit animation and for each frame... move both views to the same point...
i hope that this "solution" helps the community..
Upvotes: 1