Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rotation size and origin #44

Open
Bejil opened this issue Feb 20, 2017 · 8 comments
Open

Rotation size and origin #44

Bejil opened this issue Feb 20, 2017 · 8 comments

Comments

@Bejil
Copy link

Bejil commented Feb 20, 2017

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.

@nimati
Copy link
Owner

nimati commented Feb 21, 2017

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.

@Bejil
Copy link
Author

Bejil commented Feb 21, 2017

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];
}

@nimati
Copy link
Owner

nimati commented Feb 28, 2017

Interesting workaround @Bejil!

@rolandtolnay
Copy link

rolandtolnay commented Apr 12, 2017

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

@nimati
Copy link
Owner

nimati commented May 3, 2017

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

@nimati
Copy link
Owner

nimati commented Aug 7, 2017

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!

@kkristof200
Copy link

kkristof200 commented Dec 20, 2017

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];
}

@ThakarRajesh
Copy link

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

@nimati nimati added this to the FCAlertView 1.5 milestone Apr 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants