2

I am animating a view that is sliding down. In the view there is a simple UIButton. The view and the button have fixed widths and heights (I checked with adding a color as background). Although when use:

[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        //Slide Down the notification
        CGRect notificationsRect = self.notificationContainerView.bounds;
        notificationsRect.origin.y = 0;
        notificationViewController.view.frame = notificationsRect;
    } completion:^(BOOL finished) {
        [notificationViewController didMoveToParentViewController:self];
        self.currentNotification = notificationViewController; 
}];

then the view slides down perfectly, expect for that the text in the UIButton kind of fades in. It starts really small and animates to the correct font size.

How can I disable the animation of the text in the UIButton?

Ruud Visser
  • 3,381
  • 2
  • 20
  • 19

2 Answers2

0

Is the effect you have something similar to what is below? I tried to imitate your situation by having a view with a UIButton inside with some some text set for the title of the button. I then animated the button similarly to the way you did. As you can see there isn't really a fade happening on the text of my button inside my view that is sliding so I wonder if there is something else at play for you. I have the code I used below also to mock the situation.

enter image description here

- (void)viewDidLoad {
    [super viewDidLoad];
    self.myView = [[UIView alloc] initWithFrame:CGRectMake(200, 0, 100, 100)];
    self.myView.backgroundColor = [UIColor greenColor];
    UIButton *myButton= [[UIButton alloc] initWithFrame:CGRectMake(10, 0, 80, 80)];
    myButton.backgroundColor = [UIColor blueColor];
    [myButton setTitle:@"fun times" forState:UIControlStateNormal];
    [self.myView addSubview:myButton];
    [self.view addSubview:self.myView];

    UIButton *resetButton = [[UIButton alloc] initWithFrame:CGRectMake(300, 300, 50, 50)];
    resetButton.backgroundColor = [UIColor blackColor];
    [resetButton addTarget:self action:@selector(reset) forControlEvents:UIControlEventTouchUpInside];

    UIButton *goButton = [[UIButton alloc] initWithFrame:CGRectMake(300, 100, 50, 50)];
    goButton.backgroundColor = [UIColor redColor];
    [goButton addTarget:self action:@selector(go) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:goButton];
    [self.view addSubview:resetButton];
}

- (void)reset {
    [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        //Slide Up the notification
        CGRect notificationsRect = self.myView.bounds;
        notificationsRect.origin.y = 0;
        notificationsRect.origin.x = 200;
        self.myView.frame = notificationsRect;
    } completion:nil];
}

- (void)go {
    [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        //Slide Down the notification
        CGRect notificationsRect = self.myView.bounds;
        notificationsRect.origin.y = 200;
        notificationsRect.origin.x = 200;
        self.myView.frame = notificationsRect;
    } completion:nil];
}
Colin
  • 198
  • 3
  • 12
-1

Disable animations for UIButton using setAnimationsEnabled:(BOOL)enabled

Reference:https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/index.html#//apple_ref/occ/clm/UIView/setAnimationsEnabled:

Zahid
  • 552
  • 3
  • 11