核心动画块中按钮标题动画的值

时间:2011-03-30 07:41:49

标签: iphone core-animation

我正在使用UIButton来表示放置按钮时向上/向下滑动的表格栏上的通知数量。按钮的标题动态变化以表示未读取通知的数量。

请参阅附带的部分截图。

启动动画帧 - 通知显示为2 - 正确 Start Frame of Animation - Notifications showing as 2 - Correctly

动画的结束帧 - 显示为0的通知 - 这不应该改变 End Frame of Animation - Notifications Showing as 0 - This should not change

以下是我用于制作动画的代码

-(IBAction) showNotifications { 
    if (notificationTableIsUp) {        
        CGRect notificationsHeaderFrame = notificationsHeader.frame;
        CGRect notificationsTableFrame = notificationsTable.frame;

        // Animate to pull up Notification Table 
        [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.4];
            notificationTableIsUp = !notificationTableIsUp;

        notificationsHeaderFrame.origin.y += 220;
        notificationsHeader.frame = notificationsHeaderFrame;
        notificationsTableFrame.origin.y += 220;    
        notificationsTable.frame = notificationsTableFrame;

        [UIView commitAnimations];

    } else {
        CGRect notificationsHeaderFrame = notificationsHeader.frame;
        CGRect notificationsTableFrame = notificationsTable.frame;

        // Animate to pull down Notification Table 
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.4];
        notificationTableIsUp = !notificationTableIsUp;

        notificationsHeaderFrame.origin.y -= 220;
        notificationsHeader.frame = notificationsHeaderFrame;
        notificationsTableFrame.origin.y -= 220;    
        notificationsTable.frame = notificationsTableFrame;

        [UIView commitAnimations];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    notificationTableIsUp = NO;
    [self updateNotificationBadgeTo:2];
}

- (void) updateNotificationBadgeTo:(NSInteger)numberOfNotifications {
    notificationBadgeButton.titleLabel.font = [UIFont boldSystemFontOfSize:14];
    notificationBadgeButton.titleLabel.textColor = [UIColor whiteColor];
    notificationBadgeButton.titleLabel.text = [NSString stringWithFormat:@"%d", numberOfNotifications]; 
}

请注意,绿色栏是UIView,而通知是UILabel,圆形按钮是在IB中设置的UIButton。 0是IB中设置的按钮的初始标题。我在viewDidLoad中将它设置为2.

这里的基本问题是当我点击按钮时,它的值从白色2(在viewDidLoad中设置)变为蓝色0(在IB中设置)。

如何在向上/向下设置幻灯片动画时删除此部分?

由于 开发。

1 个答案:

答案 0 :(得分:0)

目前尚无解决方案。完全删除此功能:(