开发者

Moving a View Up

开发者 https://www.devze.com 2023-01-15 17:46 出处:网络
Ok, this might sound simple, but somehow I can\'t get this function to work . - (void)setViewMovedUp:(BOOL)movedUp {

Ok, this might sound simple, but somehow I can't get this function to work .

- (void)setViewMovedUp:(BOOL)movedUp {

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.5];

    CGRect rect = self.view.frame;
    NSLog(@"%f",self.view.frame.size.height);
    if (movedUp)
    {
        NSLog(@"test Moved Up");
        rect.origin.y += 60;
        rect.size.height -= 300;
    }
    self.view.frame = rect ;
    NSLog(@"%f after:",self.view.frame.size.height);

    [UIView commitAnimations];

}

All the NSLog开发者_如何转开发s are printing results fine and "Test Moved Up" appears so I know there is nothing wrong upstream .

This function is part of the implementation file of my MainViewController ( which manages the root view of my Window app ) .

I assume I have to call : self.view.frame, right ?

No error or warning appears, but it just doesn`t move despite printing out the logs correctly ..

Edit, this is the hierarchy in IB :

Moving a View Up


Edit again : I'm actually wondering if I'm allowed to move that view up, are we allowed to move views up if they are at the top of the hierarchy ? Then what would be revealed behind ?


Try removing just the three animation messages.

If it moves (I think it won't, but ...)

  1. Try passing in @"moveup" as the first argument to beginAnimations
  2. Try using setAnimationCurve

If it doesn't move

  1. Is the view inside another view that sets a layout for this view?
  2. Are you calling this inside the main thread (not in a background thread)

EDIT: Update

You shouldn't need to do this, but try

[self.view setNeedsDisplay];

If that doesn't work, try it on the window. Changing the frame is supposed to do this automatically.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号