gpt4 book ai didi

ios - 如何在 ViewController 之间传递 UIButton 的框架和原点

转载 作者:行者123 更新时间:2023-11-29 12:13:50 24 4
gpt4 key购买 nike

我想做一个从日历放大的动画,特别是原点和帧大小是委托(delegate)今天日期的按钮的大小。下面是用于确定 CalendarMonthView.m 中的 todayButton 的代码:

 NSDate *date = (weekdayOffset > 0) ? [_monthStartDate dateByAddingTimeInterval:-1 * weekdayOffset * D_DAY] : _monthStartDate;
BOOL bEnabled = (weekdayOffset == 0);

CGRect buttonFrame = CGRectMake (0, 0, 81, 61);
int idx = -1 * weekdayOffset;

for (int y = 0; y < 6; y++) {
buttonFrame.origin.x = 0;
for (int x = 0; x < 7; x++) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.tag = idx++;
[button setFrame:buttonFrame];
[button setBackgroundImage:[UIImage imageNamed:@"calendarFlyout_dayContainer_today.png"] forState:UIControlStateSelected];
[button setBackgroundImage:[UIImage imageNamed:@"calendarFlyout_selected.png"] forState:UIControlStateHighlighted];
button.titleLabel.font = [UIFont fontWithName:@"TitilliumWeb-Regular" size:18.0];
button.titleLabel.textAlignment = NSTextAlignmentCenter;
// TODO: optimize performance
int dayOfMonth = (int)[_calendar component:NSCalendarUnitDay fromDate:date];
if (dayOfMonth < prevDayOfMonth) {
bEnabled = !bEnabled;
}
prevDayOfMonth = dayOfMonth;

[button setTitle:[NSString stringWithFormat:@"%d", dayOfMonth] forState:UIControlStateNormal];
[button setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
[button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateDisabled];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];

[button setBackgroundImage:[UIImage imageNamed:((bEnabled) ? @"calendarFlyout_dayContainer_insideMonth.png"
: @"calendarFlyout_dayContainer_outsideMonth.png")]
forState:UIControlStateNormal];

// button.enabled = bEnabled;
button.selected = [date isToday];
if (button.selected == NO) {
button.highlighted = (_currentDayDate) ? [date isEqualToDateIgnoringTime:_currentDayDate] : NO;
} else {
// Set buttonHolder to today
}
[button addTarget:self action:@selector (dayButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
[_dayButtonsHolderView addSubview:button];
buttonFrame.origin.x += buttonFrame.size.width;
date = [date dateByAddingTimeInterval:D_DAY];
}
buttonFrame.origin.y += buttonFrame.size.height;
}

- (IBAction)dayButtonTapped:(id)sender
{
if (_delegate) {
UIButton *button = (UIButton *)sender;
NSDate *selectedDate = [_monthStartDate dateByAddingDays:button.tag];
[_delegate performSelector:@selector (calendarMonthView:dateSelected:) withObject:self withObject:selectedDate];
}
}

我想获取 button 的框架,并在 CalendarFlyoutView.m 中使用的动画中使用它。

我是 iOS 编程的新手,我阅读了一些委托(delegate)信息并通过 segues 传递信息,但这似乎对我没有帮助。

如有任何帮助,我们将不胜感激。

最佳答案

使用转换 功能。

//在年历中设置动画 _yearCalendarView.hidden = NO; self.curMonthView.monthLabel.hidden = YES;

    CalendarMonthView *monthView = [CalendarMonthView new];
monthView.delegate = self;
CGRect buttonFrame = _currentDayButtonFrame;
_yearCalendarView.frame = CGRectMake(buttonFrame.origin.x, buttonFrame.origin.y + buttonFrame.size.height, buttonFrame.size.width, buttonFrame.size.height);

NSLog(@"_yearCalendarView frame: %@", NSStringFromCGRect(_yearCalendarView.frame));

_yearCalendarView.transform = CGAffineTransformMakeScale(0.01, 0.01);
[UIView animateWithDuration:kAnimation_ExpandCalendarDuration delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
_yearCalendarView.transform = CGAffineTransformIdentity;
_yearCalendarView.frame = CGRectMake(_monthSwiperScrollView.frame.origin.x, _monthBarImageView.frame.size.height + 20, _monthSwiperScrollView.frame.size.width + 2, _yearFlyoutHeight);

} completion:^(BOOL finished) {
[UIView setAnimationDelegate:self];

[UIView setAnimationDidStopSelector:@selector (yearCalendarAnimationDidStop:finished:context:)];

}];

关于ios - 如何在 ViewController 之间传递 UIButton 的框架和原点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32488101/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com