johnno1962 / injectionforxcode

Runtime Code Injection for Objective-C & Swift
MIT License
6.55k stars 565 forks source link

It doesn't work well with function layoutSubviews #211

Open zhangqingyv opened 7 years ago

zhangqingyv commented 7 years ago
- (void)layoutSubviews
{
    [super layoutSubviews];

    [self.dealIDLabel sizeToFit];
    self.dealIDLabel.bottom = self.contentView.bottom - 8.0f;
    self.dealIDLabel.left = 10.0f;

//    add these code, then start injection ,and the layout  won't change 
//    self.dealIDLabel.centerY = self.contentView.height/2;
//    self.dealIDLabel.left = self.contentView.width/2;

    [self.indexBackgroundImageView sizeToFit];
    self.indexBackgroundImageView.bottom = self.contentView.bottom - 8.0f;
    self.indexBackgroundImageView.right = SCREEN_WIDTH - 10.0f;

    [self.currentIndexLabel sizeToFit];
    self.currentIndexLabel.top = self.indexBackgroundImageView.top + 2.0f;
    self.currentIndexLabel.left = self.indexBackgroundImageView.left + 8.0f;

    [self.totalCountLabel sizeToFit];
    self.totalCountLabel.right = self.indexBackgroundImageView.right - 10.0f;
    self.totalCountLabel.bottom = self.indexBackgroundImageView.bottom - 4.0f;
}
johnno1962 commented 7 years ago

Do you have a -injected method to recall layoutSubviews?

zhangqingyv commented 7 years ago

NO, But I pop then push to reload the whole page and UI.

It works well with -layoutSubview on the others except UITableViewCell , in my project so far.

johnno1962 commented 7 years ago

Not sure how I can help you. Seems like an iOS problem though it could be to do with reusing cells and their classes or something. When a class injects there are two versions of the class. You have to be careful not to create the injected version but the main version which has been swizzled.