ios - 如何从主视图中的特定位置淡入 UIVIew

标签 ios objective-c uiview uianimation

我的应用目前有两种模式,一种是月 View ,它显示月份中的每个日期 (1->31),而当您单击一个按钮时,日历会转变为显示每个月的年 View 。我想要做的是在年模式下,当我单击返回月模式时,我想加载当前月份的月 View ,同时从该月淡入。

这是月 View : enter image description here

当您单击顶部标题栏(2015 年 9 月)时,年度 View 会从顶部动画显示

这是年 View :

enter image description here

TLDR:当您在月 View 中单击顶部标题栏时,我想加载年历 View 并从以蓝色突出显示的日期位置(在本例中为 9 月 2 日)扩大该 View 。 这是我目前拥有的

- (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];
        }
    }
}

基本上,我想知道如何从特定位置加载和扩大 View ,以及如何将 View 缩小和折叠到特定位置。

谢谢!

最佳答案

如果我明白你在问什么,你想要这样的东西

_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
                             }];

关于ios - 如何从主视图中的特定位置淡入 UIVIew,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32359463/

相关文章:

ios - 实现复杂的自定义 View Controller 的正确方法是什么

ios - Alamofire/Moya SSL 请求因 ATS 系统信任失败而失败。 X 的系统信任失败

ios - UIView subview 放置

ios - viewForHeaderInSection 滚动时消失

objective-c - 在 Interface Builder 中使用单例?

objective-c - 在我的 xib 文件中委托(delegate)给文件所有者是什么意思?

ios - 使用 WebRTC 使用 ReplayKit 发送 iOS 设备的屏幕截图

ios - 如何将日期格式化为 IST?

iphone - iPhone Appstore批准错误

uiview - 如何使用 CAKeyframeAnimation 对形状的 CoreGraphics 绘图进行动画处理