滚动时的淡入淡出效果

用户名

当用户滚动galleryViewController从服务器获取数据的my时我想添加淡入淡出效果我无法对自己的投影机执行淡入淡出效果scrollViewController

代码:

#import "GrillGalleryCollectionViewController.h"
#import "AFNetworking.h"
@interface GrillGalleryCollectionViewController ()

@end

@implementation GrillGalleryCollectionViewController
@synthesize scrollView,pageControl, colors;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
 //   colors=[[NSArray alloc]init];
    colors = [[NSArray alloc] init];;

    [self getActiveOffers];
   // NSArray *colors = [NSArray arrayWithObjects:[UIColor redColor], [UIColor greenColor], [UIColor blueColor], nil];

}

- (void)scrollViewDidScroll:(UIScrollView *)sender {
    // Update the page when more than 50% of the previous/next page is visible
    CGFloat pageWidth = self.scrollView.frame.size.width;
    int page = floor((self.scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
    self.pageControl.currentPage = page;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)changePage:(id)sender {
    CGRect frame;
    frame.origin.x = self.scrollView.frame.size.width * self.pageControl.currentPage;
    frame.origin.y = 0;
    frame.size = self.scrollView.frame.size;
    [self.scrollView scrollRectToVisible:frame animated:YES];
}

- (IBAction)backBtnPressed:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
    pageControlBeingUsed = NO;
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    pageControlBeingUsed = NO;
}

- (void) getActiveOffers {

    NSString *string = @"http://znadesign.com/appcenter/api.php?function=get_gallery&customer_id=1";
    NSLog(@"%@", string);
    NSURL *url = [NSURL URLWithString:string];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];

    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFJSONResponseSerializer serializer];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        int total_count = (int)[[responseObject valueForKey:@"total_count"] integerValue];
        if (total_count > 0) {
            NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:total_count];
            for (int i = 1; i <= total_count; i++) {
                NSString *key = [NSString stringWithFormat:@"%i", i];
                id object = [responseObject objectForKey:key];
                [array addObject:object];
            }
            colors = [NSArray arrayWithArray:array];
            [self setSizeSliding];
           // [myTableView reloadData];
        }
        else
        {
            UIAlertView *alertView2 = [[UIAlertView alloc] initWithTitle:@"There is no internet connection."
                                                                message:nil
                                                               delegate:nil
                                                      cancelButtonTitle:@"OK"
                                                      otherButtonTitles:nil];
            [alertView2 show];
        }

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

        // 4
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"There is no internet connection."
                                                            message:[error localizedDescription]
                                                           delegate:nil
                                                  cancelButtonTitle:@"Ok"
                                                  otherButtonTitles:nil];
        [alertView show];
    }];

    // 5
    [operation start];

}

-(void) setSizeSliding
{
    for (int i = 0; i < colors.count; i++) {
        CGRect frame;
        frame.origin.x = self.scrollView.frame.size.width * i;
        frame.origin.y = 0;
        frame.size = self.scrollView.frame.size;

        //  UIView *subview = [[UIView alloc] initWithFrame:frame];
        //  subview.backgroundColor = [colors objectAtIndex:i];
        //   NSString *imageURLString=[[offersArray objectAtIndex:indexPath.row] valueForKey:@"picture"];

        NSString*slidingImage = [[colors objectAtIndex:i] valueForKey:@"picture"];
        NSURL *url = [NSURL URLWithString:slidingImage];
        NSData *data = [[NSData alloc] initWithContentsOfURL:url];
        UIImage *tmpImage = [[UIImage alloc] initWithData:data];

        UIImageView *slidingImageView = [[UIImageView alloc]initWithFrame:frame];
        slidingImageView.image = tmpImage;
        [self.scrollView addSubview:slidingImageView];
    }

    self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * colors.count, self.scrollView.frame.size.height);


}
@end

我想实现类似的淡入淡出效果,如下所示:

  [UIView animateWithDuration:2
                         animations:^{imageView.alpha = 0.0;}
                         completion:^(BOOL finished){ [imageView removeFromSuperview];}];
Naveen Prasad R

您具有代码是否可以添加以下代码,然后尝试动画是否起作用。

-(void) animateSubViews
{
    int buffer = 10;
    CGRect frame = CGRectMake((self.pageControl.currentPage * self.scrollView.frame.size.width)-buffer, 0, self.scrollView.frame.size.width + buffer, self.scrollView.frame.size.height);
   [UIView animateWithDuration:0.4 
                     animations:^{
                          for (UIView *view in self.scrollView.subviews)
                          {
                             if (CGRectContainsRect(frame, view.frame))
                             {
                                [view setAlpha:1.0];
                             }
                             else
                             {
                                [view setAlpha:0.0];
                             }
                          }
                    }];
}

尝试从ScrollView调用此方法来滚动和更改页面。

- (IBAction)changePage:(id)sender {
    CGRect frame;
    frame.origin.x = self.scrollView.frame.size.width * self.pageControl.currentPage;
    frame.origin.y = 0;
    frame.size = self.scrollView.frame.size;
    [self.scrollView scrollRectToVisible:frame animated:YES];

   //Call to animate
   [self animateSubViews];
}

- (void)scrollViewDidScroll:(UIScrollView *)sender 
{
    // Update the page when more than 50% of the previous/next page is visible
    CGFloat pageWidth = self.scrollView.frame.size.width;
    int page = floor((self.scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
    self.pageControl.currentPage = page;

   //Call to animate
   [self animateSubViews];
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

重复淡入淡出效果不起作用

来自分类Dev

AVAssetExportSession和淡入淡出效果

来自分类Dev

下拉菜单中的淡入淡出效果

来自分类Dev

Bootstrap水平菜单在悬停时具有淡入淡出效果

来自分类Dev

圆滑的转盘-淡入淡出效果不起作用

来自分类Dev

libGDX灰度着色器淡入淡出效果

来自分类Dev

如何消除jQuery工具提示的淡入淡出效果

来自分类Dev

改变基于滚动的淡入淡出吗?

来自分类Dev

在滚动div上逐渐淡入淡出

来自分类Dev

实现交叉淡入淡出的图像效果

来自分类Dev

如何使用FFMPEG在叠加中添加淡入淡出效果?

来自分类Dev

点击时的淡入淡出图像过渡

来自分类Dev

当“ .top”类滚动到150px时,我希望“ .title”类淡入淡出

来自分类Dev

悬停时淡入淡出效果-边界半径不起作用

来自分类Dev

AVAssetExportSession和淡入淡出效果

来自分类Dev

淡入淡出效果与爬升文字

来自分类Dev

当滚动时,ios uitableview淡入淡出底部单元格和顶部单元格

来自分类Dev

图像缩放和淡入淡出效果

来自分类Dev

使“淡出滑块”上的淡入淡出效果更加漂亮

来自分类Dev

如何插入淡入淡出效果?

来自分类Dev

当上下滚动时,淡入淡出会闪烁

来自分类Dev

如何减慢淡入淡出效果?

来自分类Dev

悬停具有淡入淡出效果时交换图像

来自分类Dev

滚动时非线性淡入淡出?

来自分类Dev

当“点击”Jquery时淡入淡出类

来自分类Dev

加载时淡入淡出 div 背景

来自分类Dev

折叠视差滚动效果在淡入淡出时不显示动画

来自分类Dev

为 onmouseover 添加淡入淡出效果

来自分类Dev

Div 在超时淡入淡出时闪烁