[英]Set animation for a dynamically created UIView
我已經弄清楚了如何動態添加UIView的大部分內容,但是現在當單擊uibutton並顯示uiview時,我一直試圖創建alpha動畫。 不知道我在這里缺少什么:
- (void)buttonPressedAction:(id)sender
{
CGRect frame;
frame.origin.x = 0;
frame.origin.y = 0;
frame.size = self.scrIcon.frame.size;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
UIView* view = [[UIView alloc] initWithFrame:frame];
view.alpha = 1.0;
[UIView commitAnimations];
view.backgroundColor = [UIColor redColor];
[scrIcon addSubview:view];
/*
UIStoryboard* sb = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]];
CategoryViewController* theView = [sb instantiateViewControllerWithIdentifier:@"categoryIdentifier"];
theView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:theView animated:YES];*/
}
scrIcon是一個UIScrollView
謝謝
您可以嘗試以下方法:animateWithDuration:animations:
UIView *view = [[UIView alloc] initWithFrame:self.scrIcon.frame];
view.backgroundColor = [UIColor redColor];
view.alpha = 0.0;
[scrIcon addSubview:view];
[UIView animateWithDuration:1.0 animations:^{
view.alpha = 1.0;
}];
修改您的代碼將視圖1st添加到scrIcon。 然后執行動畫。
- (void)buttonPressedAction:(id)sender
{
CGRect frame;
frame.origin.x = 0;
frame.origin.y = 0;
frame.size = self.scrIcon.frame.size;
UIView* view = [[UIView alloc] initWithFrame:frame];
view.alpha = 0.0f;
view.backgroundColor = [UIColor redColor];
[scrIcon addSubview:view];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
view.alpha = 1.0;
[UIView commitAnimations];
}
在ViewDidLoad中:只需初始化您的視圖…..
YourAnimateView = [[UIView alloc]initWithFrame:CGRectMake(-320, 0, 320, 320)];
[self.view addSubview:YourAnimateView];
In Your Button Action Method : just put this
[UIView animateWithDuration:0.5 delay:0.1
options:UIViewAnimationOptionTransitionCurlDown
animations:^{
//animation code
YourAnimateView.frame = CGRectMake(0, 0, 320, 345);
} completion:^(BOOL finished) {
//completion code
}];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.