FCAlertView icon indicating copy to clipboard operation
FCAlertView copied to clipboard

Rotation size and origin

Open Bejil opened this issue 8 years ago • 8 comments

I have a problem rotating my device with an alert added to the window. The alert is no longer centered and the background view is no longer the right size. Same with keyboard opened when having a textField.

Bejil avatar Feb 20 '17 11:02 Bejil

Hi @Bejil, Thanks for using FCAlertView and for pointing out this issue. I will look into it and let you know once it's fixed.

nimati avatar Feb 21 '17 01:02 nimati

A dirty fix would be to handle device rotation notifications and keyboard notifications. I don't know if it covers all cases, but for me it works for rotation with and without keyboard displayed.

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(detectOrientation) name:UIDeviceOrientationDidChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShowNotification:) name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHideNotification:) name:UIKeyboardDidHideNotification object:nil];

-(void)detectOrientation{

    CGSize result = [[UIScreen mainScreen] bounds].size;

    CGRect lc_frame = self.frame;
    lc_frame.size=CGSizeMake(result.height,result.width);
    self.frame = lc_frame;

    lc_frame = _alertBackground.frame;
    lc_frame.size=CGSizeMake(result.height,result.width);
    _alertBackground.frame = lc_frame;

    alertViewContents.center=alertViewContents.superview.center;
}

-(void)keyboardDidShowNotification:(NSNotification*)aNotification{

    [UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
	
        CGSize result = [[UIScreen mainScreen] bounds].size;
	
        CGRect lc_frame = self.frame;
        lc_frame.size=CGSizeMake(result.width,result.height-[[[aNotification userInfo] valueForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height);
        self.frame = lc_frame;
	
        lc_frame = _alertBackground.frame;
        lc_frame.size=CGSizeMake(result.width,result.height);
        _alertBackground.frame = lc_frame;
	
        alertViewContents.center=alertViewContents.superview.center;
	
    } completion:nil];
}

-(void)keyboardDidHideNotification:(NSNotification*)aNotification{

    [UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
	
	CGSize result = [[UIScreen mainScreen] bounds].size;
	
	CGRect lc_frame = self.frame;
	lc_frame.size=result;
	self.frame = lc_frame;
	
	lc_frame = _alertBackground.frame;
	lc_frame.size=result;
	_alertBackground.frame = lc_frame;
	
	alertViewContents.center=alertViewContents.superview.center;
	
    } completion:nil];
}

Bejil avatar Feb 21 '17 08:02 Bejil

Interesting workaround @Bejil!

nimati avatar Feb 28 '17 23:02 nimati

@nimati Any updates on this feature? Would be a great addition to an otherwise polished and very simple control!

rolandtolnay avatar Apr 12 '17 11:04 rolandtolnay

Hi there, this feature is under dev and should be released soon!

nimati avatar May 03 '17 03:05 nimati

Hi there, FCAlertView has been updated with some new features. This one is still on the radar for next release as it is a bit more trickier. Please feel free to contribute to the library if you've found a solution for it. Thanks!

nimati avatar Aug 07 '17 02:08 nimati

For the orientation change this should be ok. Similar to @Bejil's solution, but shorter.

Add to your init method:

[NSNotificationCenter.defaultCenter addObserver:self
                                           selector:@selector(orientationChanged)
                                               name:UIDeviceOrientationDidChangeNotification
                                             object:nil];

And add these 2 methods:

- (void)orientationChanged {
    _alertBackground.frame = UIScreen.mainScreen.bounds;
    alertViewContents.center = self.superview.center;
}
- (void)dealloc {
    [NSNotificationCenter.defaultCenter removeObserver:self];
}

kkristof200 avatar Dec 20 '17 19:12 kkristof200

i have implement in @kkristof200 given two method but my landscape and portrait issue not resolved img_0086 img_0088

ThakarRajesh avatar Aug 23 '18 06:08 ThakarRajesh