I have a multiview application and i have built a custom panelview controller to display panels with limited information about a product, the problem is that there should be 3 panels in portrait aspect and 4 in landscape.
Due to the depth of view controllers (about 5) the didRotateFromInterfaceOrientation: event will not trigger on the child viewcontroller so i am using the NSNotificationCenter on the rootViewController to post a message and picking it up with the child controller.
I can move the panels (UIScrollViews) without trouble but they move into place when i want them to but they move instantly which isn’t smooth or tidy, i want them to slide into their new location.
After some searching i am still having no luck finding out how to do this.
-(void) updatePanelLocations{
int buttonWidth = 230;
int buttonHeight = 335;
float frameWidth = mainPanel.frame.size.width;
int numberOfcolumns = frameWidth / buttonWidth;
float margin = (frameWidth - (numberOfcolumns * buttonWidth)) / (numberOfcolumns +1);
int currentRow = 0;
int currentColumn = 0;
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:kCATransitionReveal];
[animation setDuration:0.4];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
int i = 0;
for (UIView* curView in [mainPanel subviews]) {
//set an arbutrary tag field in generating the scrollviews so i can detect this
if (curView.tag != 9991) continue;
//newline detection
if (currentColumn == numberOfcolumns){
currentRow++;
currentColumn = 0;
}
[[curView layer] addAnimation:animation forKey:@"transitionViewAnimation"];
//XY Coordinates
int buttonX = (margin * (currentColumn + 1)) + (buttonWidth * currentColumn);
int buttonY = (margin * (currentRow + 1)) + (buttonHeight * currentRow);
//make the frame
[curView setFrame:CGRectMake(buttonX, buttonY, buttonWidth, buttonHeight)];
[curView setAutoresizingMask: UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin];
//put the button on the target uiscrollview
[[curView layer] removeAnimationForKey:@"transitionViewAnimation"];
//next column
currentColumn++;
i++;
}
animation = nil;
}
How can animate this movement for sliding from a to b??
Or better still if i have it all wrong, point me in the right direction 🙂
Cheers
What you’re looking for is
UIView‘sanimateWithDuration:methods.You’ll get the appropriate duration from
willRotateToInterfaceOrientation:duration:in the view controller.