0
votes

I have the following which works fine for somethlike a UIImageView. I am not sure if a UIView animation would work with a contained controller? I know I am animating the view's frame but just not sure if this would / should work (the below code is just proof-of-concept). But even if it did, the below is not working. Any ideas on why not?

thx in advance

edit #1 I've added a screen shot that shows a custom view controller in yellow with the phrase holla in it. As you can see the below code aniamtes the frame but not the elements of that view controller. Is this intended? Is there a workaround?

#import "MyViewController.h"

@interface ViewController ()
  @property (nonatomic, strong) MyViewController *firstIV;
@end

- (void)viewDidLoad
{
  [super viewDidLoad];


  // lets add a few UIImageViews that we will animate
  MyViewController *tmpFirstIV=[[MyViewController alloc] init];
  tmpFirstIV.view.backgroundColor=[UIColor yellowColor];
  tmpFirstIV.view.frame=CGRectMake(10.0f, 10.0f, 100.0f, 100.0f);
  self.firstIV=tmpFirstIV;
  [self addChildViewController:self.firstIV];
  [self.view addSubview:self.firstIV.view];
  [self.firstIV didMoveToParentViewController:self.firstIV];


-(void)updateAction:(id) sender{
  NSLog(@"Here are some results");
  if([self.updateButton.currentTitle isEqualToString:@"update this"]){
     [UIView animateWithDuration:6.0f animations:^{  // yeah I know, long animation
       self.firstIV.view.frame=CGRectMake(10.0f, 10.0f, 100.0f, 0.0f);
     }];
     [self.updateButton setTitle:@"make bigger" forState:UIControlStateNormal];
   }else{
     [UIView animateWithDuration:6.0f animations:^{  // equally long
       self.firstIV.view.frame=CGRectMake(10.0f, 10.0f, 100.0f, 100.0f);
     }];
     [self.updateButton setTitle:@"update this" forState:UIControlStateNormal];
   }
}

enter image description here

edit2

doesn't seem to be doing anything... will look into this layer.

-(void)viewWillLayoutSubviews { [super viewWillLayoutSubviews];

CGRect viewBounds = self.view.bounds;
self.myLabel.frame = CGRectMake(100.0f,viewBounds.size.height-20.0f,50.0f,50.0f);

}

1

1 Answers

0
votes

You are only animating the frame of the yellow box, not the label. The frame of the label will not change just because its superview's frame has changed. You either need to:

  1. Write code to animate both objects when the button is tapped
  2. Write code to automatically move the label when the box is resized, typically by overriding your view controller's - (void)viewWillLayoutSubviews method.
  3. If you're targeting iOS 6 only, you can use the new auto-layout feature. Ray Wenderlich has an excellent tutorial.