如何从主视图中的特定位置淡入 UIVIew
How to fade in a UIVIew from a specific location in the Main View
我的应用程序目前有两种模式,一种是月视图,它显示月份中的每个日期 (1->31),而当您单击一个按钮时,日历会转变为显示每个月的年视图。我想要做的是在年模式下,当我单击返回月模式时,我想加载当前月份的月视图,同时从该月淡入。
这是月视图:
当您单击顶部的 header 栏(2015 年 9 月)时,年度视图会从顶部动画显示
这是年视图:
TLDR:当您在月视图中单击顶部 header 栏时,我想加载年历视图并从日期的位置(在本例中为 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];
}
}
}
基本上,我想知道如何从特定位置加载和扩大视图,以及如何将视图缩小和折叠到特定位置。
谢谢!
如果我明白你的要求,你想要这样的东西
_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
}];
如果我对你的问题的理解正确,你想要添加和删除具有相同帧(位置)的两个视图的动画。
假设您有两个视图: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(显示)和删除view2(隐藏)。您可以更改为其他方式。
我的应用程序目前有两种模式,一种是月视图,它显示月份中的每个日期 (1->31),而当您单击一个按钮时,日历会转变为显示每个月的年视图。我想要做的是在年模式下,当我单击返回月模式时,我想加载当前月份的月视图,同时从该月淡入。
这是月视图:
当您单击顶部的 header 栏(2015 年 9 月)时,年度视图会从顶部动画显示
这是年视图:
TLDR:当您在月视图中单击顶部 header 栏时,我想加载年历视图并从日期的位置(在本例中为 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];
}
}
}
基本上,我想知道如何从特定位置加载和扩大视图,以及如何将视图缩小和折叠到特定位置。
谢谢!
如果我明白你的要求,你想要这样的东西
_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
}];
如果我对你的问题的理解正确,你想要添加和删除具有相同帧(位置)的两个视图的动画。
假设您有两个视图: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(显示)和删除view2(隐藏)。您可以更改为其他方式。