UIView 动画

来源:互联网 发布:车载数据监控系统 编辑:程序博客网 时间:2024/05/16 07:32

(一)

[UIView beginAnimations:nil context:nil];

[UIView setAnimationDuration:0.75];       //设置动画时间

[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp                forView:self.view cache:YES];                        // 动画效果

 

[UIView setAnimationDelegate:self];              //设置代理 

[UIView setAnimationDidStopSelector:@selector(addScrollViewAction)];//动画停止后指向一个方法,必须添加了上一句代码,该行才有效果

[UIView commitAnimations];



(二)

 

[UIView animateWithDuration:0.3 animations:^{   //老封面渐隐效果

        for (UIView *view in [self.scrollView subviews]) {

            if (view.tag != 200) {

                view.alpha = 0;

            }

        }

    } completion:^(BOOL finished){

        //移除老封面

        for (UIView *view in [self.scrollView subviews]) {

            if (view.tag != kScrollViewbackgroundViewTag) {

                [view removeFromSuperview];

            }

        }

        //添加新封面

        for (int i =0 ; i<categoryCount; i++) {

            NSString *categoryId = (NSString*)[categoryIdArray objectAtIndex:i];

            CGRect mgzViewRect = CGRectMake(i%10%5*(self.scrollView.frame.size.width/5)+(i/10)*self.scrollView.frame.size.width,i%10/5*(self.scrollView.frame.size.height/2),self.scrollView.frame.size.width/5,self.scrollView.frame.size.height/2);

            MgzsView *mgzsView = [[MgzsView alloc]initWithFrame:mgzViewRect

                                                  andCategoryId:categoryId];

            mgzsView.alpha = 0;

            [self.pageArray addObject:mgzsView];

            [self.scrollView addSubview:mgzsView];

            [mgzsView release];

        }

        

        [UIView animateWithDuration:0.3 animations:^{   //新封面渐显效果

            for (UIView *view in [self.scrollView subviews]) {

                if (view.tag != kScrollViewbackgroundViewTag) {

                    view.alpha = 1;

                }

            } 

        }];

    }];

0 0
原创粉丝点击