开发者

how animate frames when set editing

开发者 https://www.devze.com 2023-04-06 08:31 出处:网络
I want to smooth transition checkBox and noteButton like textLabel. I tried this code but do not work:

I want to smooth transition checkBox and noteButton like textLabel. I tried this code but do not work:

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {

    if (self.editing == NO) {
        self.checkBox.frame = CGRectMake(50, 0, 50, 50);
        self.noteButton.frame = CGRect开发者_如何学PythonMake(100, 0, 50, 50);
        self.textLabel.frame =  CGRectMake(95,0, 213, 48);
    } else {
        self.checkBox.frame = CGRectMake(10, 0, 50, 50);
        self.noteButton.frame = CGRectMake(50, 0, 50, 50);
        self.textLabel.frame =  CGRectMake(95,0, 213, 48);
    }
    [super setEditing:editing animated:animated];
}


This should work.

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    [UIView beginAnimations:@"ResizeAnimation" context:NULL];
    [UIView setAnimationDuration:0.7f];
    if (self.editing == NO) {
        self.checkBox.frame = CGRectMake(50, 0, 50, 50);
        self.noteButton.frame = CGRectMake(100, 0, 50, 50);
        self.textLabel.frame =  CGRectMake(95,0, 213, 48);
    } else {
        self.checkBox.frame = CGRectMake(10, 0, 50, 50);
        self.noteButton.frame = CGRectMake(50, 0, 50, 50);
        self.textLabel.frame =  CGRectMake(95,0, 213, 48);
    }
    [UIView commitAnimations];
    [super setEditing:editing animated:animated];
}


Try doing it in

- (void) layoutSubviews {
  if (self.editing == NO) {
    self.checkBox.frame = CGRectMake(50, 0, 50, 50);
    self.noteButton.frame = CGRectMake(100, 0, 50, 50);
    self.textLabel.frame =  CGRectMake(95,0, 213, 48);
  } else {
    self.checkBox.frame = CGRectMake(10, 0, 50, 50);
    self.noteButton.frame = CGRectMake(50, 0, 50, 50);
    self.textLabel.frame =  CGRectMake(95,0, 213, 48);
  }
}
0

精彩评论

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