iPhone loading view "slide effect" - iphone

I would to achieve that when you request something in my app (like a button pressed or whatever) I would like it to appear a small rectangle that says "loading.." and when the loading is completed it disappear with a "slide up effect". I've made a simple mockups for describing well what I'm trying to achieve. Do you have any hint for me? Thanks.
NOTE: I don't want pull to refresh effect (the loading view appears without the screen scrolling, it appears for example when you send a comment)
UPDATE:
I've tried the Cirrostratus code:
- (IBAction)displayLoadingScreen:(id)sender
{
NSLog(#"pressed");
UIView *loadingView = [[UIView alloc] init];
loadingView.frame = CGRectMake(0,-40,320,40);
[loadingView setBackgroundColor:[UIColor blueColor]];
[self.view addSubview:loadingView];
//animate in within some method called when loading starts
[UIView animateWithDuration:1.0
animations:^{
loadingView.frame = CGRectMake(0,0,320,40);
}
completion:^(BOOL finished) {
}];
for (int i = 0; i < 10000; i++) {
NSLog(#"%d", i);
}
//animate out within some method called when loading ends
[UIView animateWithDuration:1.0
animations:^{
loadingView.frame = CGRectMake(0,-40,320,40);
}
completion:^(BOOL finished){
}];
}
Why the loading view slide in after the for loop? If you try it, before it prints the for loop and after executes the two animations. Ideas?
UPDATE 2
- (void)stopLoading {
[UIView animateWithDuration:1.0
animations:^{
loadingView.frame = CGRectMake(0,-40,320,40);
}
completion:^(BOOL finished){
}];
}
- (void)startLoading {
loadingView.frame = CGRectMake(0,-40,320,40);
[loadingView setBackgroundColor:[UIColor blueColor]];
[self.view addSubview:loadingView];
//animate in within some method called when loading starts
[UIView animateWithDuration:1.0
animations:^{
loadingView.frame = CGRectMake(0,0,320,40);
}
completion:^(BOOL finished) {
}];
sleep(5);
[self stopLoading];
}
- (IBAction)displayLoadingScreen:(id)sender
{
NSLog(#"button pressed");
[self startLoading];
}

loadingView.frame = CGRectMake(0,-40,320,40);
[loadingView setBackgroundColor:[UIColor blueColor]];
[self.view addSubview:loadingView];
//animate in within some method called when loading starts
[UIView animateWithDuration:1.0
animations:^{
loadingView.frame = CGRectMake(0,0,320,40);
}
completion:^(BOOL finished){
}];
//animate out within some method called when loading ends
[UIView animateWithDuration:1.0
animations:^{
loadingView.frame = CGRectMake(0,-40,320,40);
}
completion:^(BOOL finished){
}];

What I would do is add a view in front of your other views with the loading design you want.
Then when the loading is finished (use a notification or just call a function of the view), slide it up with that kind of animation :
[UIView animateWithDuration:0.3
delay:0
options:UIViewAnimationOptionAllowUserInteraction
animations:^{
//change the frame to make the view go out of the screen
}
completion:^(BOOL finished){
//do whatever you want with the view (release it for instance)
}];

you can do it with the help of spinner else you take just view and set animation with its coordinate when you click on any object it will popup n your view and after completion of loading it you have to set '-' coordinate(frame) for your popup view hop it will hekp you......

Related

How to repeat animation from current state not from startingstate?

I want to move my UIView from left to right in a repeatedly till the view not reached at the boundary of the right side. the below code running repeatedly but move only 5 points and repeat from starting point i want to repeat from last current state and the +5 to move further.
CGPoint pos = mover.center;
pos.x=25;
int count = 25;
[UIView beginAnimations:nil context:NULL];
pos.x=count;
[UIView setAnimationDuration:0];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationRepeatCount:INFINITY];
//[UIView setAnimationRepeatAutoreverses:YES];
// CGPoint pos = mover.center;
//pos.x +=5;
count = (pos.x+=5);
mover.center = pos;
i want to see object moving in +5 points interval.
and i'm new in objective c and iphone so please help me as fast as possible .
basically my task is move view on the border of the screen mean (left to right ,up to down ,right to left and down to up) means move view in in sequence and through border of the screen of simulator repeatedly.
i hope your answer helpful to me and other who is new in this technology(iPhone).
thank you very much.
To move view from one position to another i would set its frame inside animation block. Something like this would help you:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// `customView` is a UIView defined in .h file
customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
customView.backgroundColor = [UIColor redColor];
[self.view addSubview:customView];
[self rotateViewInSelfBoundary];
}
-(void)rotateViewInSelfBoundary
{
CGRect screen = [[UIScreen mainScreen] bounds];
// Top Left to top right
[UIView animateWithDuration:3.0f
animations:^{
[customView setFrame:CGRectMake(screen.size.width - customView.frame.size.width, 0, 100, 100)];
}
completion:^(BOOL finished)
{
// Top right to bottom right
[UIView animateWithDuration:3.0f
animations:^{
[customView setFrame:CGRectMake(screen.size.width - customView.frame.size.width, screen.size.height - customView.frame.size.height, 100, 100)];
}
completion:^(BOOL finished)
{
// bottom right to bottom left
[UIView animateWithDuration:3.0f
animations:^{
[customView setFrame:CGRectMake(0, screen.size.height - customView.frame.size.height, 100, 100)];
}
completion:^(BOOL finished)
{
// bottom left to top left
[UIView animateWithDuration:3.0f
animations:^{
[customView setFrame:CGRectMake(0, 0, 100, 100)];
}
completion:^(BOOL finished)
{
// call the same function again.
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:#selector(rotateViewInSelfBoundary) object:nil];
[self performSelector:#selector(rotateViewInSelfBoundary) withObject:nil afterDelay:0.0f];
}];
}];
}];
}];
}
Screen shots:
use UIViewAnimationOptionBeginFromCurrentState like
[UIView animateWithDuration:1.0f
delay:2.0f
options:UIViewAnimationOptionRepeat | UIViewAnimationOptionBeginFromCurrentState
animations:^{
//your animation
}
completion:nil];
If you want to move the view in a square, define the four CGPoint values it should animate between and then:
NSArray *values = #[[NSValue valueWithCGPoint:point0],
[NSValue valueWithCGPoint:point1],
[NSValue valueWithCGPoint:point2],
[NSValue valueWithCGPoint:point3],
[NSValue valueWithCGPoint:point0]];
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:#"position"];
animation.values = values;
animation.duration = 5.0;
animation.repeatCount = HUGE_VALF;
[mover.layer addAnimation:animation forKey:#"moveAroundBorder"];
This will take care of all of the moving of the view with no further intervention on your part.
If you want to use the iOS 7 block-based key-frame animation, it would be:
[UIView animateWithDuration:5.0 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{
[UIView animateKeyframesWithDuration:5.0 delay:0.0 options:UIViewKeyframeAnimationOptionRepeat | UIViewKeyframeAnimationOptionCalculationModeLinear animations:^{
[UIView addKeyframeWithRelativeStartTime:0.00 relativeDuration:0.25 animations:^{
mover.center = point0;
}];
[UIView addKeyframeWithRelativeStartTime:0.25 relativeDuration:0.25 animations:^{
mover.center = point1;
}];
[UIView addKeyframeWithRelativeStartTime:0.50 relativeDuration:0.25 animations:^{
mover.center = point2;
}];
[UIView addKeyframeWithRelativeStartTime:0.75 relativeDuration:0.25 animations:^{
mover.center = point3;
}];
} completion:nil];
} completion:nil];
Note the curious nesting of animateKeyframesWithDuration within the animateWithDuration. That's because the UIViewKeyframeAnimationOptionCalculationModeLinear curiously does not stop the "ease in / ease out" behavior, so you have to specify UIViewAnimationOptionCurveLinear on the outer animation block.

Custom UIView doesn't get removed from superview when loaded again while animating

The question explains it all actually.
I load a custom UIView on top of my current view, animated, using this code:
- (void)showView
{
self.blurView.alpha = 0.f;
[UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionAllowUserInteraction animations:^
{
self.blurView.alpha = 1.f;
} completion:^(BOOL finished) {
[UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionAllowUserInteraction animations:^
{
self.blurView.alpha = 0.f;
} completion:nil];
}];
}
It works, but when I perform -(void)showView again while it is still animating, the custom view doesn't get removed from the screen.
It just stays like this:
I figured out what the problem was.
blurView is a public variable and every time I did -(void)showView it used the same variable, setting the alpha to 0.f just once, thus never changing the alpha of the first show.
I declared the variable blurView in the method itself and now it works because every blurView gets it's own pointer.
-(void)someMethod
{
//Create a live blur view
FXBlurView *blurView = [[FXBlurView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
blurView.center = CGPointMake(self.view.window.frame.size.width / 2, self.view.window.frame.size.height / 2);
blurView.layer.cornerRadius = 20.f;
[self.view.window addSubview:blurView];
[self showView:(blurView)];
}
- (void)showView:(FXBlurView *)blurView
{
//Make full transparent before showing
blurView.alpha = 0.f;
//Start animation
[FXBlurView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionAllowUserInteraction animations:^
{
blurView.alpha = 1.f;
} completion:^(BOOL finished) {
if (finished)
{
//End animation
[FXBlurView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionAllowUserInteraction animations:^
{
blurView.alpha = 0.f;
} completion:nil];
}
}];
}
You should add to the top of your function this line:
[self.view.layer removeAllAnimations];
It will remove all of the active animations.
It doesn't work because you have implemented a delay, use animation block with delay - it will create animation keys that could be removed with this function above.
[UIView animateWithDuration:0.3 delay:0.0
options:UIViewAnimationOptionAllowUserInteraction
animations:^
{
// ...
} completion:NULL];

UIButton always moves back to its first location?

I am having this hair pulling problem, i hope anybody will be able to help me out. it seems like a little thing but i have not been able to find any solution.
I have a UIButton that i want to move around with a animation block. Everytime i click the button i have it move to a new location, the button always moves to the correct location the problem is that it always moves from its first location to its new location.
lets say that i have a button at (0,0) i then move it to (0,50) works like a beaut!
Now i want to move the button to (0,100) and i expect it to animate from (0,50) to (0,100) but what it does it animate from (0,0) to (0,100) so it ends up in the right location, but moves FROM the wrong location.
i move the UIButton by setting a a new frame in a animation block
[UIView animateWithDuration:0.5f
delay:0.0f
options:UIViewAnimationCurveLinear
animations:^{
}
completion:nil];
in my case i move the button in a completion block when other controls a finished moving.
i really hope somebody out there knows exatly what im talking about and have the answer for me.
the code i use for animating the uibutton is this, the buttons name is "btnAddPhoneNumber" and its also the "sender"
[UIView animateWithDuration:1
delay:0
options:UIViewAnimationCurveLinear
animations:^{
txtNewPhoneNumber.frame = CGRectMake(newXnumber, newYnumber, txtPhoneNumber.frame.size.width, txtPhoneNumber.frame.size.height);
}
completion:^(BOOL finished) {
txtNewPhoneNumber.placeholder = #"here you go!";
//animate add textfield button.
[UIView animateWithDuration:0.5f
delay:0
options:UIViewAnimationCurveLinear
animations:^{
[sender setFrame:CGRectMake(btnAddPhoneNumber.frame.origin.x, newYnumber, btnAddPhoneNumber.frame.size.width, btnAddPhoneNumber.frame.size.height)];
txtNewPhoneNumberTitle.frame = CGRectMake(newXtitle, newYtitle, txtPhoneNumberTitle.frame.size.width, txtPhoneNumberTitle.frame.size.height);
[btnDelete setFrame:btnDeleteRect];
}
completion:^(BOOL finished) {
}];
}];
thank you for reading my question, and for helping me find a solution.
EDIT (added code example)
Try adding UIViewAnimationOptionBeginFromCurrentState to the options of the second animation, see if it solves your problem.
[UIView animateWithDuration:0.5f
delay:0.0f
options:UIViewAnimationCurveLinear | UIViewAnimationOptionBeginFromCurrentState
animations:^{
}
completion:nil];
Another way to go would be to set the frame of the button again (to the same value) in the completion handler of the second animation.
Check this work around. As I mentioned in comments, you can use this as your last option. Not a recommended approach.
[UIView animateWithDuration:1
delay:0
options:UIViewAnimationCurveLinear
animations:^{
txtNewPhoneNumber.frame = CGRectMake(newXnumber, newYnumber, txtPhoneNumber.frame.size.width, txtPhoneNumber.frame.size.height);
}
completion:^(BOOL finished) {
txtNewPhoneNumber.placeholder = #"here you go!";
[self performSelector:#selector(callSecondAnimation) withObject:nil afterDelay:1.5f)]; //or 0.5f
}];
- (void)callSecondAnimation {
//animate add textfield button.
[UIView animateWithDuration:0.5f
delay:0
options:UIViewAnimationCurveLinear
animations:^{
[sender setFrame:CGRectMake(btnAddPhoneNumber.frame.origin.x, newYnumber, btnAddPhoneNumber.frame.size.width, btnAddPhoneNumber.frame.size.height)];
txtNewPhoneNumberTitle.frame = CGRectMake(newXtitle, newYtitle, txtPhoneNumberTitle.frame.size.width, txtPhoneNumberTitle.frame.size.height);
[btnDelete setFrame:btnDeleteRect];
}
completion:^(BOOL finished) {
}];
}
Update:
Try this first,
[UIView animateWithDuration:1
delay:0
options:UIViewAnimationCurveLinear
animations:^{
txtNewPhoneNumber.frame = CGRectMake(newXnumber, newYnumber, txtPhoneNumber.frame.size.width, txtPhoneNumber.frame.size.height);
}
completion:^(BOOL finished) {
txtNewPhoneNumber.placeholder = #"here you go!";
txtNewPhoneNumber.frame = CGRectMake(newXnumber, newYnumber, txtPhoneNumber.frame.size.width, txtPhoneNumber.frame.size.height);//try setting it here once and then call next one
[self callSecondAnimation];
}];
- (void)callSecondAnimation {
//animate add textfield button.
[UIView animateWithDuration:0.5f
delay:0
options:UIViewAnimationCurveLinear
animations:^{
[sender setFrame:CGRectMake(btnAddPhoneNumber.frame.origin.x, newYnumber, btnAddPhoneNumber.frame.size.width, btnAddPhoneNumber.frame.size.height)];
txtNewPhoneNumberTitle.frame = CGRectMake(newXtitle, newYtitle, txtPhoneNumberTitle.frame.size.width, txtPhoneNumberTitle.frame.size.height);
[btnDelete setFrame:btnDeleteRect];
}
completion:^(BOOL finished) {
}];
}
I found the problem, the view used AutoLayout, when i removed the tick in AutoLayout the new position of my button is saved, and the next animation continues from the previously location.
thanks to ACB and Tobi for their input their helped me try different solutions that ended up fixing the problem!

addsubview after another subview

I know its mad but here it goes:
i load a splashView to my app: on viewDidLoad:
[self.view addSubview:splashView];
UIViewAnimationOptions options = UIViewAnimationOptionCurveLinear;
[UIView animateWithDuration:0.5 delay:3.0 options:options animations:^{
splashView.alpha = 0.0f;
splashView.frame = CGRectMake(512,384,-10,-10);
}
completion:^(BOOL finished){
[splashView removeFromSuperview];
}];
Nothing special to the code here.
however, when i try to load the same view as an action through a button
NOTHING happens:
-(IBAction)showSplash:(id)sender {
[self.view addSubview:splashView];
UIViewAnimationOptions options = UIViewAnimationOptionCurveLinear;
[UIView animateWithDuration:0.5 delay:3.0 options:options animations:^{
splashView.alpha = 0.0f;
splashView.frame = CGRectMake(512,384,-10,-10);
}
completion:^(BOOL finished){
[splashView removeFromSuperview];
}];
}
why is this happening?
By the way if i DO NOT load the splashView on the viewDidLoad and then use the button (action) it works ok!
is this normal behavior?
Reset the alpha value before fading the splash view out.
splashView.alpha = 1.0f;

UIView removeFromSuperview

The removeFromSuperview method actually pulls off the image very quickly, is there a way to remove it in a animated fashion. thanks
If you're targeting iOS4 (code snippet from UIView docs):
[UIView animateWithDuration:0.2
animations:^{ table.alpha = 0.0; }
completion:^(BOOL finished){ [table removeFromSuperview]; }];
code example here
http://www.iphonedevsdk.com/forum/iphone-sdk-development/37467-removefromsuperview-animation-transition.html
1) insert your new subview (index of 0 so it's hidden) onto the view stack.
[window insertSubview:myNewView atIndex:0];
2) Then animation the view out (straight from the docs) is:
[UIView animateWithDuration:0.2
animations:^{ view.alpha = 0.0; }
completion:^(BOOL finished){ [view removeFromSuperview]; }]