2017-01-05 2 views
1

iOSアプリケーションに以下のアニメーションを追加する必要があります。UITableViewと一緒にスクロールバーを使用してトップアニメーションとボトムアニメーションを達成しましたが、4,UIViewsが単一のアニメーションパート水平線。助言がありますか?目的のCでビューベースのアニメーションを作成する方法は?

http://www.image-maps.com/m/private/0/af8u4ulika9siddnf6k6hhrtg2_untitled-2.gif

コード: -

@implementation AnimatedView { 
    UIScrollView *mainScroll; 
    UIScrollView *backgroundScrollView; 

    UILabel *_textLabel; 
    UITableView *_commentsTableView; 

    UIView *menuView; 
    UIView *_commentsViewContainer; 
    UIView *fadeView; 

    UIImageView *imageView; 

    NSMutableArray *comments; 
} 

- (id)init { 
    self = [super init]; 
    if (self) { 

     _mainScrollView = [[UIScrollView alloc] initWithFrame:[UIApplication sharedApplication].keyWindow.frame]; 
     self.view = _mainScrollView; 

     _backgroundScrollView = [[UIScrollView alloc] initWithFrame:HEADER_INIT_FRAME]; 
     imageView = [[UIImageView alloc] initWithFrame:HEADER_INIT_FRAME]; 
     fadeView = [[UIView alloc] initWithFrame:imageView.frame]; 
     _textLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0f, 100.0f, 150.0f, 25.0f)]; 
     menuView = [[UIView alloc] initWithFrame:CGRectMake(0,_textLabel.frame.size.height+150, self.view.frame.size.width+30, 180)]; 

     [_backgroundScrollView addSubview:imageView]; 
     [_backgroundScrollView addSubview:fadeView]; 
     [_backgroundScrollView addSubview:menuView]; 
     [_backgroundScrollView addSubview:_textLabel]; 

     _commentsViewContainer = [[UIView alloc] init]; 
     _commentsTableView = [[UITableView alloc] init]; 
     _commentsTableView.scrollEnabled = NO; 
     _commentsTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; 

     [self.view addSubview:_backgroundScrollView]; 
     [_commentsViewContainer addSubview:_commentsTableView]; 
     [self.view addSubview:_commentsViewContainer]; 

     // fake data! 
     comments = [@[@"Array for tableview"] mutableCopy]; 

    } 
    return self; 
} 

#pragma mark Scroll 

- (void)scrollViewDidScroll:(UIScrollView *)scrollView { 
    CGFloat delta = 0.0f; 
    CGRect rect = HEADER_INIT_FRAME; 

    // Here is where I do the "Zooming" image and the quick fade out the text and toolbar 

    if (scrollView.contentOffset.y < 0.0f) { 

     delta = fabs(MIN(0.0f, _mainScrollView.contentOffset.y)); 
     _backgroundScrollView.frame = CGRectMake(CGRectGetMinX(rect) - delta/2.0f, CGRectGetMinY(rect) - delta, CGRectGetWidth(rect) + delta, CGRectGetHeight(rect) + delta); 
     [_commentsTableView setContentOffset:(CGPoint){0,0} animated:NO]; 

    } else { 
     delta = _mainScrollView.contentOffset.y; 
     _textLabel.alpha = 1.0f; 
     CGFloat backgroundScrollViewLimit = _backgroundScrollView.frame.size.height - kBarHeight; 

     // Here I check whether or not the user has scrolled passed the limit where I want to stick the header, if they have then I move the frame with the scroll view 
     // to give it the sticky header look 

     if (delta > backgroundScrollViewLimit) { 

      _backgroundScrollView.frame = (CGRect) {.origin = {0, delta - _backgroundScrollView.frame.size.height + kBarHeight}, .size = {self.view.frame.size.width, HEADER_HEIGHT}}; 
      _commentsViewContainer.frame = (CGRect){.origin = {0, CGRectGetMinY(_backgroundScrollView.frame) + CGRectGetHeight(_backgroundScrollView.frame)}, .size =       _commentsViewContainer.frame.size }; 
      _commentsTableView.contentOffset = CGPointMake (0, delta - backgroundScrollViewLimit); 
      CGFloat contentOffsetY = -backgroundScrollViewLimit * kBackgroundParallexFactor; 
      [_backgroundScrollView setContentOffset:(CGPoint){0,contentOffsetY} animated:NO]; 
     } 
     else { 
      _backgroundScrollView.frame = rect; 
      _commentsViewContainer.frame = (CGRect){.origin = {0, CGRectGetMinY(rect) + CGRectGetHeight(rect)}, .size = _commentsViewContainer.frame.size }; 
      [_commentsTableView setContentOffset:(CGPoint){0,0} animated:NO]; 
      [_backgroundScrollView setContentOffset:CGPointMake(0, -delta * kBackgroundParallexFactor)animated:NO]; 
     } 
    } 
} 

- (void)viewDidAppear:(BOOL)animated { 
    _mainScrollView.contentSize = CGSizeMake(CGRectGetWidth(self.view.frame), _commentsTableView.contentSize.height + CGRectGetHeight(_backgroundScrollView.frame)); 
} 
+0

何よりも優れていますか? –

+0

@rckoenesは現在の達成部分を追加しました。 – iOS91

+0

コードを投稿し、より良いと思う場所を指定します。 – rckoenes

答えて

0

あなたは本当にこれを実装するために、任意のscrollviewを必要としません。必要なのは1 UITableViewと2セクションのみです。最初のセクションには空の要素が1つあります(行の高さは0に設定されています)。 headerViewsにはUIViewを使用できます。次に、テーブルビューのデリゲートscrollViewDidScrollに基づいて、ヘッダーの高さをアイコンの位置合わせで変更するだけです。 scrollViewDidScrollは、TableViewの要素の1つがUIScrollViewから継承するため、UITableViewのデリゲートです。

関連する問題