sliding bar in iOS, like facebook when losing network connection - iphone

I need to provide a sliding bar in iOS to alert the user that he entered wrong data.
I want it to appear for about 1 second at the top of the screen and then disappear, so something with animcation and commit. but I couldn't find any good documentation for this.
Any ideas?
Thanks.

First you need an imageView of your notification bar or a button to be animating, which is yourObject.
With this method you put the banner on screen (change coordinates to whatever suites you) Also if you want it flip down as Apple has some of their notifications you can use the rotation, if not just delete that line.
//yourObject setHidden to NO
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.5];
self.yourObject.center = CGPointMake(100, 200);
self.yourObject.transform = CGAffineTransformMakeRotation(0);
[UIView commitAnimations];
Next just make a timer which after 1 second invokes some method to do the opposite of the one I have posted.
if you want a very simple appear and disappear instead of sliding you can replace the two lines before commitAnimations with
yourObject.alpha=1

Related

in ios dev, how to handle case based animations?

My questions is probably best asked by stating my problem:
In my app, there are two button choices, lets say 1 & 2. when you click and hold on 1, 2 fades out (alpha change) over .3 seconds, and vice versa.
If the user 'cancel's' that button touch (by dragging his finger away from the button and releasing) the opposite button fades back in.
This all works great. The problem arises when the user does not hold down on the button, and clicks it so a touch is registered in under .3 seconds (the time it takes for the other button to fade out) The thing is there are more animations that have to happen after all this so i guess my issue is that animations further down the line interrupt that .3 sec fade and things start to look awkward.
Suggestions to work with this? Thank you!
As suggested in this post, you should create a secondary UIView animation that goes to the same animation endpoint as your 0.3 second one. Make sure you set the animation to begin from the current state, and give it as short as time as it will let you. Basically this will get your views to all look like they would at the end of that first animation, and it will happen much more quickly. After that animation is done, you would do your other animations based on the button results.
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.03];
[UIView setAnimationCurve: UIViewAnimationCurveLinear];
// here you set your view and animation stuff from the other animation that takes 0.3 seconds
[UIView commitAnimations];
This will get you quickly to the state you would be in after the 0.3 second animation and you can begin the animation from there.

Effect like deletion in ios

I need hint/code like deletion/move app effect on iOS, normally i have started the code, I am using UIButton list in UIScroll.
So my question is that supposes I have 8 to 10 button in screen and i want to change their position with dragging. for example choose 6th button and move or set to between 1 and 2. when I put them in to between the position of other button will change.
I am using UIPanGestureRecognizer for dragging.
download, Tiles-v1.0.zip, and check code, this is what i used when i needed to implement that.
reference: Move UIViews to avoid collision like rearranging icons on Springboard
If you already have the code for dragging, the rest is easy. Just use UIView Animation.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
...
[button setFrame:newFrame];
...
[UIView commitAnimations];
Basically, just move your buttons to the their new positions in that beginAnimations - commitAnimations block.
Hope this helps.

iPhone app - white box adapting size dynamically, depending on content

I'm trying to build my first iPhone app, a Berlin museum guide, and I'm having a little trouble figuring out how to design a specific view. I did mockups of all my views with Photoshop before, but now actually making it happen in Xcode is something else, of course :-)
So, here's what I want:
[I was gonna post an image here but since I'm new I don't have enough reputation to post images.]
Find the image here:
http://img9.uploadhouse.com/fileuploads/13445/13445099d5adea77b02fe1d76755da6b81c92634.png
I want a white box with several text parts in it. A large heading, a smaller heading and a longer text that is placed next to an image. The text that goes in there is provided by my core data model and changes depending on what exhibition the user is looking at.
First question: Is there such thing as a "white box with rounded corners object" in which I can place text, images etc. or would I have to import this as a custom image? In that case, I'd have a problem if I want the box to change it's size, as with simply scaling the image the round corners would become distorted.. I'm assuming a CSS-stye approach with a top- and bottom-image and doing the middle part with a repeat-y property or something like that won't work in objective-c, right?
Second question: Does anyone have good advice on how to approach the text expand thing in general? I want the description text to initially be just a teaser so it won't take up the whole screen. If the user wants to keep reading, on tapping the "more" button the box should expand and display the entire text.
So much for the theory.. I'm a bit clueless about how to get this done and am hoping that somebody might have some good input on that.
Thanks a lot for taking the time to help a newbie :-)
I would not use a b/g image since there are going to be problems with vertical expansion, as you noted yourself. I would rather use a regular UIView and following method to make its corners round.
#import <QuartzCore/QuartzCore.h>
view.layer.cornerRadius = 5;
As for the text expansion. I would not try to make image wrapping text as it is hard.
For automatica UITextView adjustment you can do the following.
set UITextView frame smaller.
create a button "more" that will change the frame of the UITextView and animate it
example:
#define MOVE_ANIMATION_DURATION_SECONDS 0.5
-(void)maximize:(BOOL)animated{
if(animated){
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:MOVE_ANIMATION_DURATION_SECONDS];
[UIView setAnimationDelegate:self];
[self setMaximizedViewState];
[UIView commitAnimations];
}else
[self setMaximizedViewState];
}
-(void)minimize:(BOOL)animated{
if(animated){
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:MOVE_ANIMATION_DURATION_SECONDS];
[UIView setAnimationDelegate:self];
[self setMinimizedViewState];
[UIView commitAnimations];
}else
[self setMinimizedViewState];
}
-(void)setMinimizedViewState{
isMinimized = YES;
//Adjust the UITextView's frame and other properties
}
-(void)setMaximizedViewState{
isMinimized = NO;
//Adjust the UITextView's frame and other properties
}

Scrolling screen upward to expose TextView above keyboard

I think I'm missing something obvious and would appreciate an answer.
I have a view with a 2-section grouped tableView, each section having one row and a textView, the heights of the rows 335 and 140. This allows for a box with nicely rounded corners to type text into when the keyboard appears (140 height section) and when the keyboard is dismissed, a nice box to read more text (notes); most of the time, use is without the keyboard.
I also added a toolbar at the bottom of the screen to scroll up above the keyboard. A button on the toolbar dismisses the keyboard. This last part works fine with the keyboard going up and down using a notification and the following code in a keyboardWillShow method:
[UIView beginAnimations:#"showKeyboardAnimation" context:nil];
[UIView setAnimationDuration:0.50];
self.view.frame = CGRectMake(self.view.frame.origin.x,
self.view.frame.origin.y,
self.view.frame.size.width,
self.view.frame.size.height - 216);
[UIView commitAnimations];
But with the above code, the 2 sections of the tableView remain unscrolled, only the toolbar and the keyboard move. With the following code (found both in previous posts), both the toolbar and the tableView sections move.
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.50];
CGRect rect = self.view.frame;
rect.origin.y -= 216;
self.view.frame = rect;
[UIView commitAnimations];
Now I know that I have to tweak the numbers to get the everything as I want it but my first question is what is substantively different between the 2 sets of code that the sections move in the 2nd but not in the 1st? The toolbar also moves with the 2nd code.
The second question is, am I going to be able to scroll the smaller height section from off the screen to above the keyboard while at the same time moving the toolbar up just 216?
Thanks
I may be missing something here, but in the first piece of code, you are changing the height by 216. While on the 2nd piece of code, you are changing the origin of the entire view by 216 in the y-direction.
Depending on how you have the frame set in IB, the first piece of code might not move it if you don't allow it to move in that direction. Check your settings in the inspector window.
When you are saying "unscrolled" you are referring to them not changing location within the main view correct? This would be different than them actually scrolling (which you can do as well by changing scroll value).
You may want to check out the Hidden Drawer example here, since they push views in and out of the main view, sort of like a toolbar, and I think that is what you are asking. The whole "scrolling" thing is throwing me off though.
http://cocoawithlove.com/2009/05/intercepting-status-bar-touches-on.html
From memory, something like
tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight

How do I make the modal view only come up half way?

So I have an app where you play a game, and at the end it asks you your name for recording of the high score. I would like to use a modal view to accomplish this, but I am experiencing some hiccups along the way. So far, all I have is the modal view sliding up all the way to the top of the screen, but there isn't anything there yet, it's just blank:
UINavigationController *navController = [UINavigationController new];
[self presentModalViewController:navController animated:YES];
I have seen on several other iPhone apps, the ability to make the modal view come only half way up the screen (or less) and then have a textfield where you can receive input, such as for my high score list. How would I go about restricing the size of the modal view? And perhaps adding a textfield onto it? Any help would be appreciated! Thanks
What makes you think presentModalViewController was used?
You can do this quite easily with an UIViewController and animation.
Using Animation, a sample would look like something like this:
//Move Screen UP:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
self.view.frame = CGRectMake(self.view.frame.origin.x, (self.view.frame.origin.y - kTextView_Keyboard_Offset), self.view.frame.size.width, self.view.frame.size.height);
[UIView commitAnimations];
Where the "kTextView_Keyboard_Offset is defined in my Contants. You would specify/replace with your Offset value equal the number of pixels in the direction that you would like to move.
Define a full-screen view with a transparent background - then put the obscuring content wherever you like.
Then you just bring it up as you would any other modal view.