我有iPhone应用程序。
我希望在加载视图时它有subView。此外,我希望加载子视图,就像在动画中从左到右翻转或滑动一样。
subView包含UIButton和TextView。我希望subView应该像动画一样加载 从左边滑下。
答案 0 :(得分:1)
翻转视图可以按如下方式完成:
[UIView animateWithDuration:1 animation:^{
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.subView cache:FALSE];
}];
这是我的完整代码:
- (void) flipCard {
if (_isDisplayBackOfCard) {
[UIView animateWithDuration:.5 animations:^{
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:FALSE];
[self.backOfCard removeFromSuperview];
[self.view addSubview:self.frontOfCard];
} completion:^(BOOL finished){
_isDisplayBackOfCard = !_isDisplayBackOfCard;
}];
}
else {
[UIView animateWithDuration:.5 animations:^{
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:FALSE];
[self.frontOfCard removeFromSuperview];
[self.view addSubview:self.backOfCard];
} completion:^(BOOL finished){
_isDisplayBackOfCard = !_isDisplayBackOfCard;
}];
}
}
通过在动画块中设置视图框架,可以轻松实现滑动视图:
CGRect _newFrame = CGRectMake(someValueForX, someValueForY, someValueForWidth, someValueForHeight);
[UIView animateWithDuration:.5 animations:^{ [self.subView setFrame:_newFrame];}];
答案 1 :(得分:0)
你可以通过在viewDidLoad
视图方法中添加subView来实现这一点,在viewDidAppear
方法中你可以使用块语句使用动画来给它一些动画。
快乐编码:)
编辑1
这里我在XIB中添加了scrollView,将IBOutlate
附加到它。您可以通过编程方式将其添加到viewDidLoad
方法中。
首先,我通过应用此框架使视图隐藏
subCatScroll.frame = CGRectMake(320, 0, 91, 436);
点击一些按钮,我通过动画显示它(它来自iPhone的右侧边缘)
- (IBAction)done:(id)sender
{
[Appirater userDidSignificantEvent:YES];
if(pointer.hidden == YES)
{
[UIView beginAnimations:@"Move Me To Unhide" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:kAnimationDur];
subCatScroll.frame = CGRectMake(229,0,91,436);
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
[self configureView];
pointer.hidden = NO;
}
else
{
[UIView beginAnimations:@"Move Me To Hide" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:kAnimationDur];
subCatScroll.frame = CGRectMake(320, 0, 91, 436);
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
pointer.hidden = YES;
}
}
这里pointer
是一个控件,用于决定如何处理scrollView
答案 2 :(得分:0)
行。当您想要添加子视图(不是容器视图 - 我通过您的问题预测它!)时,请按照以下步骤添加滑动动画 -
IBOutlet
synethesize
他们在.m文件中。编写以下代码 -
- (void)viewWillAppear:(BOOL)animated
{
self.btn.center = CGPointMake(-430.0, 211.0);
self.txtView.center = CGPointMake(-430.0, 120.0);
[self addSubview:self.btn andMoveTo:CGPointMake(115.0, 211.0) duration:1.0 option:UIViewAnimationOptionCurveLinear];
[self addSubview:self.txtView andMoveTo:CGPointMake(40.0, 34.0) duration:1.0 option:UIViewAnimationOptionCurveLinear];
}
- (void) addSubview:(UIView*)view
andMoveTo:(CGPoint)destination
duration:(float)secs
option:(UIViewAnimationOptions)option
{
[UIView animateWithDuration:secs delay:0.0 options:option
animations:^{
view.frame = CGRectMake(destination.x,destination.y, view.frame.size.width, view.frame.size.height);
}completion:nil];
[self.view addSubview:view];
}