Spring Animations - not working


#1

I have done everything as described for Spring Animations as described in title “Spring Animations”, but I no not see any effect.
I have also added NSLog to - (void)viewDidAppear:(BOOL)animated to see is this called and it is.

Any idea what I have done wrong.

I an testing in simulator.

Thanks


#2

Same here, also on iPhone no animation, not during startup or after switching views.

Somebody has a clue?

EDIT I found it: if you change the Y-coordinate of the frame origin in loadView to 0, you will see the spring animation described in the book.


#3

Yes that was the problem, and I understand what.

But to have this animation every time when you select that view, following code is needed in the beginning of:

[code]- (void)viewDidAppear:(BOOL)animated

CGRect frame = CGRectMake(40, 0, 240, 30);
elf.textField.frame = frame;[/code]

actually then you do not need to change loadView:

my implementation:

[code]- (void)viewDidAppear:(BOOL)animated
{
NSLog(@"- (void)viewDidAppear:(BOOL)animated");

CGRect frame = CGRectMake(40, 0, 240, 30);
self.textField.frame = frame;

[super viewDidAppear];

[UIView animateWithDuration:2.0
                      delay:0.0
     usingSpringWithDamping:0.25
      initialSpringVelocity:0.0
                    options:0
                 animations:^{
                     CGRect frame = CGRectMake(40, 70, 240, 30);
                     self.textField.frame = frame;
                 }
                 completion:NULL];

}[/code]


#4

It seems that there is a typo in loadView. From the solution downloaded, the Y-coordinate is not 70, but -20.

- (void)loadView
{
    ...
    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(40, -20, 240, 30)];
    ...

#5

The reason for this is because the UITextfield frame set in the animation block is the same as the one used to initialize it

[code]- (void)loadView
{
// Create a view
CGRect frame = [UIScreen mainScreen].bounds;
BNRHypnosisView *backgroundView = [[BNRHypnosisView alloc] initWithFrame:frame];

CGRect textFieldRect = CGRectMake(40, 70, 240, 30);
UITextField *textField = [[UITextField alloc] initWithFrame:textFieldRect];

}
[/code]

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear];
    [UIView animateWithDuration:2.0 delay:0.0 usingSpringWithDamping:0.25 initialSpringVelocity:0.0 options:0 animations:^{
        CGRect frame = CGRectMake(40,70, 240, 30);
        self.textField.frame = frame;
    } completion:NULL];
}

realize both frame are the same?