FCAlertView
FCAlertView copied to clipboard
Rotation size and origin
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.
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.
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];
}
Interesting workaround @Bejil!
@nimati Any updates on this feature? Would be a great addition to an otherwise polished and very simple control!
Hi there, this feature is under dev and should be released soon!
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!
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];
}
i have implement in @kkristof200 given two method but my landscape and portrait issue not resolved