【发布时间】:2011-06-01 23:07:10
【问题描述】:
我有一个多视图应用程序,并且我已经构建了一个自定义面板视图控制器来显示具有有限产品信息的面板,问题是应该有 3 个纵向面板和 4 个横向面板。
由于视图控制器的深度(大约 5 个),didRotateFromInterfaceOrientation: 事件不会在子视图控制器上触发,因此我使用 rootViewController 上的 NSNotificationCenter 来发布消息并使用子控制器接收它。
我可以毫无问题地移动面板 (UIScrollViews),但它们会在我希望它们移动到位时移动,但它们会立即移动,不平滑或不整齐,我希望它们滑入新位置。
经过一番搜索,我仍然无法找到如何做到这一点。
-(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;
}
如何为这种从 a 滑到 b 的动作设置动画??
或者如果我都错了,请指出我正确的方向:)
干杯
【问题讨论】:
标签: iphone ipad animation uiview xcode4