2013-07-24 226 views
-1

我以编程方式创建了UIView。现在我想用动画显示视图。我的代码在下面。请注意,代码位于按钮单击事件上。uiview上的动画

view1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 284)]; 
view1.backgroundColor = [UIColor redColor]; 
[self.view addSubview: view1]; 
UIButton *cancel = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
cancel.frame = CGRectMake(265, 0, 55, 20); 
[cancel setTitle: @"Cancel" forState: UIControlStateNormal]; 
[cancel addTarget:self action:@selector(cancelView:) forControlEvents:UIControlEventTouchUpInside]; 
+0

您应该指定“动画”的含义。你想要什么动画? –

+0

我的意思是,当我点击按钮视图是通过适当的动画显示不正常 – Nasir

+0

有大量的动画可能,你应该真正澄清你想要什么。 –

回答

1

试试吧....

[UIView beginAnimations: nil context: nil]; 
[UIView setAnimationBeginsFromCurrentState: YES]; 
[UIView setAnimationDuration: 0.5]; 
view1.frame = CGRectMake(20,45,110,548); //Set frame according your choice 
[UIView commitAnimations]; 

希望我帮助。

+0

先生其工作正常,但我们可以改变动画的风格我的意思是anohter动画 – Nasir

+0

@Nasir:如果它的工作,那么你应该接受答案,放弃投票。根据您的选择设置动画时间。 –

+0

@Nasir:[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:NO]; –