davdroman / Bohr

Settings screen composing framework
MIT License
1.26k stars 83 forks source link

IOS 7 support. #16

Closed mythodeia closed 8 years ago

mythodeia commented 9 years ago

it crashes when using the layoutMargins is there any solution for apps that still support IOS 7? thanks

mythodeia commented 9 years ago

just an update: for example when i use the BOSwitchTableViewCell i changed this:

    NSLayoutConstraint *rightConstraint = [NSLayoutConstraint constraintWithItem:self.toggleSwitch
                                                                       attribute:NSLayoutAttributeRight
                                                                       relatedBy:NSLayoutRelationEqual
                                                                          toItem:self.toggleSwitch.superview
                                                                       attribute:NSLayoutAttributeRightMargin
                                                                      multiplier:1
                                                                        constant:0];

to this:

    NSLayoutConstraint *rightConstraint = [NSLayoutConstraint constraintWithItem:self.toggleSwitch
                                                                       attribute:NSLayoutAttributeRight
                                                                       relatedBy:NSLayoutRelationEqual
                                                                          toItem:self.toggleSwitch.superview
                                                                       attribute:IS_IOS8 ? NSLayoutAttributeRightMargin : NSLayoutAttributeRight
                                                                      multiplier:1
                                                                        constant:IS_IOS8 ? 0 : -16];

and in BOTableViewCell.m i modified the layoutSubviews to this:

        CGFloat yOffset;
        if (IS_IOS8) {
            yOffset = (self.layoutMargins.top-self.frame.size.height)/2;
        }
        else{
            yOffset = 0;
        }

and finally in BOTableViewController.m for method tableview:willDisplayCell:forRowAtIndexPath

        if (IS_IOS8) {
            if (cell.layoutMargins.top == 8) {
                CGFloat cellHeight = [self tableView:tableView heightForRowAtIndexPath:indexPath];
                cell.layoutMargins = UIEdgeInsetsMake(cellHeight, cell.layoutMargins.left, cell.layoutMargins.bottom, cell.layoutMargins.right);
            }
        }

is there a better way?

davdroman commented 9 years ago

Hey there @mythodeia. Thanks for opening this issue.

If you check out v3.0.0 alpha you'll see most of the layoutMargins code is gone, although it's still a vital part of Bohr because it determines cells height for expansion. I haven't really found any other more efficient, less hacky way to do it, but I'll keep looking for a better solution. When I find it, iOS 7 support will be totally achievable.

mythodeia commented 9 years ago

if you want, we can leave this issue open until IOS 7 support is fully achievable then. keep up the great work. thanks :+1:

davdroman commented 9 years ago

Sure! I'll definitely keep this open.

liuyan3176 commented 8 years ago

@mythodeia thanks for your advice. I meet this crash in iOS7 right now,but when I change the code just as you said,the crash appear again. It seems that the [xxx setPreservesSuperviewLayoutMargins] is still unrecognized selector sent to instance 0x166556c0 . Did you combat this issue in iOS7?

mythodeia commented 8 years ago

@liuyan3176 i did not have any issues with that change. However in that app i used IOS 8 and above.

davdroman commented 8 years ago

I'm afraid iOS 7 support won't be possible in the future due to my plans of releasing a major, Swify 4.0 version (#22). Sorry for that!