@@ -677,6 +677,15 @@ -(void) fixRegionAndAccesoryViews
677
677
}
678
678
}
679
679
680
+ -(UIEdgeInsets) getSafeInsets {
681
+ if (@available (iOS 11 , *)) {
682
+ return self.safeAreaInsets ;
683
+ }
684
+ else {
685
+ return UIEdgeInsetsZero;
686
+ }
687
+ }
688
+
680
689
-(UIView *) swipeContentView
681
690
{
682
691
if (!_swipeContentView) {
@@ -700,12 +709,35 @@ -(void) layoutSubviews
700
709
_swipeOverlay.frame = CGRectMake (0 , 0 , self.bounds .size .width , self.contentView .bounds .size .height );
701
710
[self fixRegionAndAccesoryViews ];
702
711
if (_swipeView.image && !CGSizeEqualToSize (prevSize, _swipeOverlay.bounds .size )) {
712
+ // refresh safeInsets in situations like layout change, orientation chage, table resize, etc.
713
+ UIEdgeInsets safeInsets = [self getSafeInsets ];
714
+ if (safeInsets.left !=0 || safeInsets.right != 0 ) {
715
+ if (_leftView) {
716
+ [self changeFrameSafe: _leftView x: -_leftView.bounds.size.width - safeInsets.left];
717
+ }
718
+ if (_rightView) {
719
+ [self changeFrameSafe: _rightView x: _swipeOverlay.bounds.size.width - safeInsets.right];
720
+ }
721
+ if (_swipeView) {
722
+ [self changeFrameSafe: _swipeView x: -safeInsets.left];
723
+ }
724
+ }
703
725
// refresh contentView in situations like layout change, orientation chage, table resize, etc.
704
726
[self refreshContentView ];
705
727
}
706
728
}
707
729
}
708
730
731
+
732
+ -(void ) changeFrameSafe : (UIView *) view x : (CGFloat ) x {
733
+ CGRect frame = view.frame ;
734
+ CGAffineTransform transform = view.transform ;
735
+ view.transform = CGAffineTransformIdentity ;
736
+ frame.origin .x = x;
737
+ view.frame = frame;
738
+ view.transform = transform;
739
+ }
740
+
709
741
-(void ) fetchButtonsIfNeeded
710
742
{
711
743
if (_leftButtons.count == 0 && _delegate && [_delegate respondsToSelector: @selector (swipeTableCell:swipeButtonsForDirection:swipeSettings:expansionSettings: )]) {
@@ -718,13 +750,15 @@ -(void) fetchButtonsIfNeeded
718
750
719
751
-(void ) createSwipeViewIfNeeded
720
752
{
753
+ UIEdgeInsets safeInsets = [self getSafeInsets ];
721
754
if (!_swipeOverlay) {
722
755
_swipeOverlay = [[UIView alloc ] initWithFrame: CGRectMake (0 , 0 , self .bounds.size.width, self .contentView.bounds.size.height)];
723
756
[self fixRegionAndAccesoryViews ];
724
757
_swipeOverlay.hidden = YES ;
725
758
_swipeOverlay.backgroundColor = [self backgroundColorForSwipe ];
726
759
_swipeOverlay.layer .zPosition = 10 ; // force render on top of the contentView;
727
- _swipeView = [[UIImageView alloc ] initWithFrame: _swipeOverlay.bounds];
760
+ CGRect bounds = _swipeOverlay.bounds ;
761
+ _swipeView = [[UIImageView alloc ] initWithFrame: CGRectMake (-safeInsets.left, bounds.origin.y, bounds.size.width, bounds.size.height)];
728
762
_swipeView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
729
763
_swipeView.contentMode = UIViewContentModeCenter;
730
764
_swipeView.clipsToBounds = YES ;
@@ -736,14 +770,14 @@ -(void) createSwipeViewIfNeeded
736
770
if (!_leftView && _leftButtons.count > 0 ) {
737
771
_leftView = [[MGSwipeButtonsView alloc ] initWithButtons: _leftButtons direction: MGSwipeDirectionLeftToRight differentWidth: _allowsButtonsWithDifferentWidth buttonsDistance: _leftSwipeSettings.buttonsDistance];
738
772
_leftView.cell = self;
739
- _leftView.frame = CGRectMake (-_leftView.bounds .size .width , _leftSwipeSettings.topMargin , _leftView.bounds .size .width , _swipeOverlay.bounds .size .height - _leftSwipeSettings.topMargin - _leftSwipeSettings.bottomMargin );
773
+ _leftView.frame = CGRectMake (-_leftView.bounds .size .width - safeInsets. left , _leftSwipeSettings.topMargin , _leftView.bounds .size .width , _swipeOverlay.bounds .size .height - _leftSwipeSettings.topMargin - _leftSwipeSettings.bottomMargin );
740
774
_leftView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight;
741
775
[_swipeOverlay addSubview: _leftView];
742
776
}
743
777
if (!_rightView && _rightButtons.count > 0 ) {
744
778
_rightView = [[MGSwipeButtonsView alloc ] initWithButtons: _rightButtons direction: MGSwipeDirectionRightToLeft differentWidth: _allowsButtonsWithDifferentWidth buttonsDistance: _rightSwipeSettings.buttonsDistance];
745
779
_rightView.cell = self;
746
- _rightView.frame = CGRectMake (_swipeOverlay.bounds .size .width , _rightSwipeSettings.topMargin , _rightView.bounds .size .width , _swipeOverlay.bounds .size .height - _rightSwipeSettings.topMargin - _rightSwipeSettings.bottomMargin );
780
+ _rightView.frame = CGRectMake (_swipeOverlay.bounds .size .width - safeInsets. right , _rightSwipeSettings.topMargin , _rightView.bounds .size .width , _swipeOverlay.bounds .size .height - _rightSwipeSettings.topMargin - _rightSwipeSettings.bottomMargin );
747
781
_rightView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight;
748
782
[_swipeOverlay addSubview: _rightView];
749
783
}
0 commit comments