在iOS 5中,使用“情节串连板”(storyboard)从屏幕底部飞入的按钮设置自定义子视图的动画
我正在尝试模拟键盘显示动画,只使用一个自定义子视图来显示用户的三个按钮。是否有任何方法可以通过脚本实现这一点(即不必以编程方式创建子视图)?快速回答 是的,不过您必须以编程方式设置一些子视图属性。您要做的是让UIViewController调用:在iOS 5中,使用“情节串连板”(storyboard)从屏幕底部飞入的按钮设置自定义子视图的动画,ios,ios5,uiviewcontroller,subviews,Ios,Ios5,Uiviewcontroller,Subviews,我正在尝试模拟键盘显示动画,只使用一个自定义子视图来显示用户的三个按钮。是否有任何方法可以通过脚本实现这一点(即不必以编程方式创建子视图)?快速回答 是的,不过您必须以编程方式设置一些子视图属性。您要做的是让UIViewController调用: [UIView animateWithDuration:animations:completion:] 详细示例 在使用键盘的任何方法的一侧,请尝试以下操作: CGFloat windowWidth = self.mainView.frame.siz
[UIView animateWithDuration:animations:completion:]
详细示例 在使用键盘的任何方法的一侧,请尝试以下操作:
CGFloat windowWidth = self.mainView.frame.size.width;
CGFloat windowHeight = self.mainView.frame.size.height;
// center myCustomSubview along the x direction, and put myCustomSubview just below the screen when UIViewController initially gets onto the screen
CGPoint offScreenBelow = CGPointMake(windowWidth/2, windowHeight + (myCustomView.frame.size.y/2));
CGPoint onScreen = CGPointMake(windowWidth/2,windowHeight/2);
// change the second argument of the CGPointMake function to alter the final height of myCustomSubview
// start myCustomSubview offscreen
myCustomSubview.center = offScreenBelow;
// make sure to add myCustomSubview to the UIViewController's view's subviews
[self.view addSubview:myCustomSubview];
float duration = 1.0; // change this value to make your animation slower or faster. (units in seconds)
// animate myCustomSubview onto the screen
[UIView animateWithDuration:duration
animations:^{
myCustomSubview.center = onScreen;
}
completion:^(BOOL finished){
// add anything you want to be done as soon as the animation is finished here
}];
确保在“ViewDidDisplay:”之后或其内部调用您的方法。
当您想让myCustomSubview动画返回屏幕外时,请确保在UIViewController中执行以下操作:
// set offscreen position same way as above
CGFloat windowWidth = self.mainView.frame.size.width;
CGFloat windowHeight = self.mainView.frame.size.height;
CGPoint offScreenBelow = CGPointMake(windowWidth/2, windowHeight + (myCustomView.frame.size.y/2));
// myCustomSubview is on screen already. time to animate it off screen
[UIView animateWithDuration:duration // remember you can change this for animation speed
animations:^{
myCustomSubview.center = offScreenBelow;
}
completion:^(BOOL finished){
[myCustomSubview removeFromSuperView];
}];
如果您的子视图未显示 与处理子视图时一样,请确保帧设置正确,子视图已添加到带有
addSubview:
的superview,子视图不为零(并且已正确初始化),并且子视图的alpha和不透明属性均未设置为0。快速回答
是的,不过您必须以编程方式设置一些子视图属性。您要做的是让UIViewController调用:
[UIView animateWithDuration:animations:completion:]
详细示例 在使用键盘的任何方法的一侧,请尝试以下操作:
CGFloat windowWidth = self.mainView.frame.size.width;
CGFloat windowHeight = self.mainView.frame.size.height;
// center myCustomSubview along the x direction, and put myCustomSubview just below the screen when UIViewController initially gets onto the screen
CGPoint offScreenBelow = CGPointMake(windowWidth/2, windowHeight + (myCustomView.frame.size.y/2));
CGPoint onScreen = CGPointMake(windowWidth/2,windowHeight/2);
// change the second argument of the CGPointMake function to alter the final height of myCustomSubview
// start myCustomSubview offscreen
myCustomSubview.center = offScreenBelow;
// make sure to add myCustomSubview to the UIViewController's view's subviews
[self.view addSubview:myCustomSubview];
float duration = 1.0; // change this value to make your animation slower or faster. (units in seconds)
// animate myCustomSubview onto the screen
[UIView animateWithDuration:duration
animations:^{
myCustomSubview.center = onScreen;
}
completion:^(BOOL finished){
// add anything you want to be done as soon as the animation is finished here
}];
确保在“ViewDidDisplay:”之后或其内部调用您的方法。
当您想让myCustomSubview动画返回屏幕外时,请确保在UIViewController中执行以下操作:
// set offscreen position same way as above
CGFloat windowWidth = self.mainView.frame.size.width;
CGFloat windowHeight = self.mainView.frame.size.height;
CGPoint offScreenBelow = CGPointMake(windowWidth/2, windowHeight + (myCustomView.frame.size.y/2));
// myCustomSubview is on screen already. time to animate it off screen
[UIView animateWithDuration:duration // remember you can change this for animation speed
animations:^{
myCustomSubview.center = offScreenBelow;
}
completion:^(BOOL finished){
[myCustomSubview removeFromSuperView];
}];
如果您的子视图未显示
与处理子视图时一样,请确保帧设置正确,子视图已添加到带有
addSubview:
的superview,子视图不为零(并且已正确初始化),并且子视图的alpha和不透明属性均未设置为0。这可能会起作用,但我在找一张单子。谢谢佩德罗!这可能行得通,但我在找一张UIAlertSheet。谢谢佩德罗!