How can I cover the entire iPhone screen with the keyboard being show? - objective-c

Imagine a simple translucent mask that I'd like to cover the whole iphone screen:
UIView *maskView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.height)];
maskView.backgroundColor = [UIColor blackColor];
maskView.alpha = 0.0f;
maskView.userInteractionEnabled = NO;
[[[UIApplication sharedApplication] keyWindow] addSubview:maskView];
[UIView animateWithDuration:.7 delay:.5f options:UIViewAnimationCurveEaseOut
animations:^{
maskView.alpha = .3f;
}
completion:^(BOOL finished) {
}];
However, the screen is displaying the keyboard ( I have made a textfiled in the view a first responder).
How can I cover the keyboard with my maskView?

Related

Repeating glow animation outside radius (like bulb glowing effect)

I am working on iPad project and I need to do animation like glowing bulb with smooth ON/ OFF effect. How can I achieve this?
I tried with UIView animation and try to get same kind of animation.
Here is code which I tried.
-(void) setGlowToView{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake((self.frame.size.width-7.f)/2.f, (self.frame.size.height-7.f)/2.f, 7.f, 7.f)];
view.backgroundColor = [UIColor whiteColor];
[self addSubview:view];
[UIView animateWithDuration:1.5 delay:0.0 options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat animations:^{
view.alpha = 0.8;
view.layer.cornerRadius = 2.2;
view.transform = CGAffineTransformMakeScale(1.8,1.8);
} completion:^(BOOL finished){
}];
}

I need to popup actionsheet above tabbar in my present viewcontroller, but it should not overlap tabbar(i need to see tabbar clearly)

I need to popup transperant actionsheet above tabbar in my present viewcontroller, but it should not overlap tabbar(i need to see tabbar clearly).
To create a transparant background on a UIActionsheet you have to set the delegate and then you can do:
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet {
[actionSheet.layer setContents:nil];
}
To create a custom UIView that animates in from the bottom you can do>
bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, 250)];
bottomView.backgroundColor = [UIColor redColor];
bottomView.hidden = YES;
[self.view addSubview:bottomView];
UIButton *testButton = [UIButton buttonWithType:UIButtonTypeCustom];
testButton.frame = CGRectMake(20, 50, 280, 40);
testButton.backgroundColor = [UIColor greenColor];
[bottomView addSubview:testButton];
[self animateBottomViewIn];
And have the following methods:
-(void)animateBottomViewIn
{
bottomView.hidden = NO;
[UIView animateWithDuration:0.3 animations:^{
bottomView.frame = CGRectMake(0, self.view.frame.size.height - bottomView.frame.size.height, self.view.frame.size.width, bottomView.frame.size.height);
} completion:^(BOOL finished) { }];
}
-(void)animateBottomViewOut
{
[UIView animateWithDuration:0.3 animations:^{
bottomView.frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, bottomView.frame.size.height);
} completion:^(BOOL finished) {
bottomView.hidden = YES;
}];
}

UIStatusBarAnimationFade duration

I have an app where I have a button that fades the screen to black. I want to have the status bar fade to black also, so I'm using the following code:
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
Is it possible for me to set the duration of the fade? If that's not doable, is it possible to get the official fade duration (like using UIKeyboardAnimationDurationUserInfoKey to get the keyboard slide duration).
Well I didn't get anything back from anyone, but I think I should at least share my hack. After some experimentation, I settled on fade out is 1 second and fade in is 0.25 seconds.
- (IBAction)fadeToBlack:(id)sender
{
UIView *view = [[[UIView alloc] initWithFrame:self.view.window.frame] autorelease];
view.backgroundColor = [UIColor blackColor];
view.alpha = 0.0;
[self.view.window addSubview:view];
// NOTE: Fading the black view at the same rate as the status bar. Duration is just a guess.
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
[UIView animateWithDuration:1.0 animations:^{
view.alpha = 1.0;
} completion:^(BOOL finished) {
[view addGestureRecognizer:self.dismissViewGesture];
}];
}
- (void)dismissViewWithGesture:(UIGestureRecognizer *)gesture
{
UIView *view = gesture.view;
[view removeGestureRecognizer:gesture];
// NOTE: Fading the black view at the same rate as the status bar. Duration is just a guess.
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
[UIView animateWithDuration:0.25 animations:^{
view.alpha = 0.0;
} completion:^(BOOL finished) {
[view removeFromSuperview];
}];
}
I had the same issue and my values are 0.5 for hiding and 0.2 for showing the navigation bar together with the status bar.
At least for iOS 6.1/iOS Simulator those values are matching the reality much better.

Overlay not scrolling with UITableView - iOS

I have a UITableView class that uses the following methods to call a loading overlay when going to the next screen. The problem is that this loading screen does not scroll with the list... So if you scroll a little bit and click on something, the loading screen doesn't show (because it's at the top). How can I get the loading screen to stay on top of the UITableView at all times? Please know that each UITableView is contained within a UINavBar, which is contained within a UITabBar. Here is my code:
-(void)createLoadScreen
{
CGRect screenRect = [self.view bounds];
CGRect overlayFrame = CGRectMake(0.0, 0.0, screenRect.size.width, screenRect.size.height);
overlay = [[UIView alloc] initWithFrame:overlayFrame];
overlay.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.7];
CGRect frame = CGRectMake(screenRect.size.width / 2 - 25.0, screenRect.size.height / 2 - 70, 25.0, 25.0);
loading = [[UIActivityIndicatorView alloc] initWithFrame:frame];
[loading setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhiteLarge];
[loading sizeToFit];
loading.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleBottomMargin);
loading.hidesWhenStopped = YES;
[overlay addSubview:loading];
}
-(void)showActivityIndicator
{
[self.view addSubview:overlay];
[loading startAnimating];
}
-(void)removeActivityIndicator {
[loading stopAnimating];
[overlay removeFromSuperview];
}
Are you using a UITableViewController?
You should be able to fix your issue by adding the overlay view to the table's superview instead of the table view itself. This way your overlay is actually above and separate from your scrolling table view
-(void)showActivityIndicator
{
[[self.view superview] addSubview:overlay];
[loading startAnimating];
}

Animated background in iOS

I want to animate my background after a view got loaded in my iOS application. This works with solid colors, but I'm not able to let it work using background images. This is my code:
- (void)viewDidLoad
{
[super viewDidLoad];
[UIView animateWithDuration:5.0 animations:^{
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"background.png"]];
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"background_dark.png"]];
}];
[UIView commitAnimations];
}
Does anyone know the correct way to do this?
Thanks
You animate things like this:
view.backgroundColor = INITIAL COLOR
[UIView animateWithDuration:5.0 animations:^{
view.backgroundColor = FINAL COLOR
}];
The animate method animates the change from the current state to whatever you set up in the animation block. The animation block is not a list of steps.
Therefore, I think what you want is this:
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"background.png"]];
[UIView animateWithDuration:5.0 animations:^{
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"background_dark.png"]];
}];
Also, do NOT call commitAnimations afterward, that's only if you're using the old-style beginAnimations method. Read the documentation, and don't just call methods to see if they work.
Not all properties can be animated like this. It is very likely that a background image is one of them. What you can do is have a second view on top with the new image and animate its alpha from 0 to 1.
Ty this:
[UIView animateWithDuration:5.0 animations:^{
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"background.png"]];
} completion:^(BOOL finished)
{
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"background_dark.png"]];
}];