1

我想出了如何动态添加 UIView 的大部分内容,但现在我被困在尝试创建 alpha 动画时,单击 uibutton 并显示 uiview。不确定我在这里缺少什么:

- (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

谢谢

4

3 回答 3

4

你可以试试这个方法: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;
}];
于 2012-10-05T04:01:27.187 回答
2

修改了您的代码,将视图 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];



}
于 2012-10-05T03:49:33.200 回答
2

在 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

                         }];
于 2012-10-05T04:15:16.747 回答