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

标签 ios objective-c delegates

我想做一个从日历放大的动画,特别是原点和帧大小是委托(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/

相关文章:

android - 从移动浏览器的初始视口(viewport)中排除 DIV

ios - 应用程序存储分配和低存储通知

objective-c - LSSharedFileListItemResolve 抛出 : "URLs with the type "nwnode :"are not supported"

objective-c - Retina 显示屏的字体大小

iphone - OSStatus 错误 -50?

c# - C#中的同步任务队列

ios - 直接编辑 UITextField.text 属性 UITextFieldDelegate 不会触发

ios - [iOS][AWS Cognito] 'logins' 已弃用 : Use "AWSIdentityProviderManager"

delegates - 使用 C++/CLI 从点击事件调用委托(delegate)

ios - 如何通过编码xcode改变按钮的位置