Search code examples
iosstoryboarduiactionsheet

annoying UIactionsheet reset all view


SET UP

  • In my view controller i have a View and 2 Buttons
  • everything positioned in a Storyboard, and linked to ViewController.h
  • STEP 1 : I push the 1st button to make the View move.
  • STEP 2 : I push the 2nd button to pop the UIActionSheet.

PROBLEM

As soon as I push the 2nd button, my View position comes back as defined in the storyboard. Here is my code :

ViewController.h

@interface ViewController : UIViewController<UIActionSheetDelegate>
@property (strong, nonatomic) IBOutlet UIView *view1;
- (IBAction)move:(id)sender;
- (IBAction)bringPop:(id)sender;

ViewController.m

#import "ViewController.h"
@interface ViewController ()
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

//move _View1
- (IBAction)move:(id)sender {
    [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
        _view1.layer.frame= CGRectMake(0, 79, 320, 489);
    } completion:nil];
}

//action sheet pops
- (IBAction)bringPop:(id)sender {
     UIActionSheet *popupQuery = [[UIActionSheet alloc] initWithTitle:@"" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"0" otherButtonTitles:@"1", @"2", @"3", nil];
    [popupQuery showInView:self.view];   
}
@end

Solution

  • You might need to overwrite the method

    -(void)layoutSubviews
    

    This method should be overwritten when the AutoLayout or AutoResizingMasks doesn't perform the layout that you require. I'm pretty sure that the UIActionSheet presents itself as a modalViewController which triggers a viewDidAppear and viewWillAppear in your actual ViewController.

    Try setting some break points and check if this methods are triggered if so then AutoLayout or AutoResizingMasks are resetting your frames as in the xib file.

    It will depend a lot on how are you building your views