2015-09-02 33 views
1

我的應用程序目前有兩種模式,一個月視圖,它顯示月份中的每個日期(1-> 31),當您單擊按鈕時,日曆轉換爲每年顯示每月的年份視圖。我想要做的是在年模式下,當我點擊返回到月模式時,我想從當月開始加載月份視圖,並從當月開始淡入。如何從主視圖中的特定位置淡入UIVIew

這是月視圖: enter image description here

當您單擊頂部標題欄(2015年9月),每年從山頂

這裏動畫中的年視圖:

enter image description here

TLDR:當您在月視圖中單擊頂部標題欄時,我想加載年份日曆視圖並從日期位置增加該視圖(在這種情況下9月2日)以藍色突出顯示。 這裏是我目前

- (IBAction)monthBarTapped:(id)sender 
{ 
    if (_monthBarImageView.highlighted) { 
     [self _animateOutYearCalendar:0]; 
     return; 
    } 
    _calendarYear = [_calendarStartDate year]; 

    [self _refreshYearCalendar]; 

    // animate in year calendar 
    _yearCalendarView.hidden = NO; 
    [_yearCalendarView setFrameHeight:0]; 
    self.curMonthView.monthLabel.hidden = YES; 

    [UIView beginAnimations:@"animateYearCalendarIn" context:nil]; 
    [UIView setAnimationDuration:0.5]; // kAnimation_AnimateInDuration]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector (yearCalendarAnimationDidStop:finished:context:)]; 

    [_yearCalendarView setFrameHeight:_yearFlyoutHeight]; 

    [UIView commitAnimations]; // start animation 

    _monthBarImageView.highlighted = YES; 
    [self _refreshMonthButton:NO]; 
} 

- (void)_animateOutYearCalendar:(long)month 
{ 
    [UIView beginAnimations:@"animateYearCalendarOut" context:nil]; 
    [UIView setAnimationDuration:0.5]; // kAnimation_AnimateInDuration]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector (yearCalendarAnimationDidStop:finished:context:)]; 

    [_yearCalendarView setFrameHeight:0]; 
    [UIView commitAnimations]; // start animation 

    if (month > 0) { 
     // set the new month/year 
     if ((month != _calendarStartDate.month) || (_calendarYear != _calendarStartDate.year)) { 
      // they changed the date 
      NSDateComponents *comps = [_calendar components:NSCalendarUnitMonth | NSCalendarUnitYear fromDate:_calendarStartDate]; 
      comps.month = month; 
      comps.year = _calendarYear; 
      _calendarStartDate = [_calendar dateFromComponents:comps]; 
      [self _refreshDisplay]; 
     } 
    } 
} 

基本上,我想知道如何加載和從一個特定的位置增加一個視圖,以及如何收縮和崩掉着眼於一個特定的位置。

謝謝!

+0

您可能想要將視圖的框架從按鈕框架動畫到屏幕的整個框架(可能不包括導航欄)。 – Aaron

+0

是的,這正是我想要做的 –

回答

1

如果我理解你的要求,你想是這樣的

_monthView.alpha = 0; 
_monthView.frame = button.frame; 
     [UIView animateWithDuration:0.5 
           delay:0.0 
          options:UIViewAnimationOptionCurveLinear 
         animations:^{ 
    // Do all the animations you want in this block 
           _monthView.frame = CGRectMake(_destination.frame.origin.x, 
                       _destination.frame.origin.y, 
                       _destination.frame.size.width, 
                       _destination.frame.size.height); 
// where destination is where you want to animate to 
           _monthView.alpha = 1.0; 

          } 
          completion:^{ 
    //call what ever method you want when animation finishes 
          }]; 
+0

400是什麼意思? –

+0

對不起,只是一個例子,如果你想將視圖400點向右移動。 –

+0

這並不真正做我想做的事情。這只是將整個幀向右移動400個像素。我試圖從一個特定的框架,這是按鈕的框架加載視圖!謝謝你的努力 –

1

如果我理解你的問題正確,你想動畫添加和所有具有相同的幀(位置)兩個視圖刪除。

假設您有兩個視圖:具有相同原點和大小的view1和view2。試試這個:

[UIView transitionWithView:self.view 
        duration:0.4 // animation duration - change this if you like 
        options:UIViewAnimationOptionTransitionCrossDissolve 
       animations:^{ 
        [self.view addSubview:view1]; // view1 is the view you wanted to show 
       } 
       completion:^(BOOL finished) { 
        [view2 removeFromSuperview]; //view2 is the view you want to hide 
       }]; 

以上是添加view1(show)和remove view2(hide)的方法。你可以改變做另一種方式。

+0

檢查編輯後的問題以獲得更清晰的效果!我認爲還有一些誤解需要做的事情。 –