Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am very new to iPhone/iPad development. can you please help me create this programmatically. I want to expand/collapse a UIView programmatically.
Anyone know how to do it or any tutorial that i can follow? I have tried to find the tutorial but couldn't find what i want.
Below is the screenshot how i want to do
Its easily done with modify the height of that View as bneely suggested..
Follow the below steps:
1.First create the second View what you posted in your question and name it "detailedView"
2.if you have the "detailedView" height = 200(for example), write the following code in viewDidLoad method,
CGRect newFrame = detailedView.frame;
newFrame.size.height = 100;
detailedView.frame = newFrame;
so when the "detailedView" load, it will be looked like the first View what you showed in your question.
3.When you click the button to expand "detailedView", within that button action just write the following code
CGRect newFrame = detailedView.frame;
if(newFrame.size.height == 100)
{
newFrame.size.height = 200;
[UIView animateWithDuration:0.25 animations:^(void){
detailedView.frame = newFrame;
}];
}
else
{
newFrame.size.height = 100;
[UIView animateWithDuration:0.25 animations:^(void){
detailedView.frame = newFrame;
}];
}
That's all.
CGRect newFrame = view.frame;
newFrame.size.height += 100;
[UIView animateWithDuration:0.25 animations:^(void){
view.frame = newFrame;
}];
Related
My application has VOIP calling. In that I want to implement animation like iPhone's default Phone application does when User Clicks on Call button on dial Pad and animation that is done on End call button.
I have researched alot about this but haven't find anything yet. Any help will be appreciated on this topic.
Right now I have implemented scaling animation like below:
- (void)animateFadingOut{
self.view.transform = CGAffineTransformMakeScale(1.00, 1.00);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self];
[self performSelector:#selector(push) withObject:nil afterDelay:0.35];
self.view.transform = CGAffineTransformMakeScale(0.00, 0.00);
//set transformation
[UIView commitAnimations];
}
- (void)push
{
self.view.transform = CGAffineTransformMakeScale(1.00, 1.00);
// push navigation controloller
CallViewController *objCallViewController = [[CallViewController alloc] initWithNibName:#"CallViewController_iPhone" bundle:nil];
[self setHidesBottomBarWhenPushed:YES];
[self.navigationController pushViewController:objCallViewController animated:NO];
[objCallViewController release];
[self setHidesBottomBarWhenPushed:NO];
[[AppDelegate shared] setTabHidden:TRUE];
}
But It is not giving me exact animation that default Phone application has
Here is what I might try if I was trying to create animations.
CGRect movementFrame = self.view.frame;
//Make position and size changes as needed to frame
movementFrame.origin.x = 0;
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
/*
Animation you want to commit go here
Apply movementFrame info to the frame
of the item we want to animate
*/
//If you wanted a fade
self.view.alpha = !self.view.alpha //Simply says I want the reverse.
self.view.frame = movementFrame;
//Example of what you could do.
self.view.transform =CGAffineTransformMakeScale(1.00, 1.00);
} completion:^(BOOL finished) {
//Things that could happen once the animation is finished
[self push];
}];
This has not been tested for your case. Therefore I am also not sure if it will help you, but hopefully it will. Good luck to you.
*Edit*
So I reviewed the animation on an iPhone and it appears to me to be a series of animations happening at once.
You have what I presume to be the UIActionSheet animating down.
The top section overlay sliding up its y-axis.
Then you have, which I haven't mastered yet, a split in the back view that animates its x-axis in opposite directions which cause the split.
Finally you have the new view scale up to take frame for the effect.
I can't say 100% this how they have done it, however if I was going to attempt to recreate this, I would likely start here.
Hello there so after just quickly coming up with an animation I got pretty close it could use some tweaks.
It took me three views to do a
topView, bottomView, and backView.
Also took into account the view that you would be loading in. viewToLoadIn
`-(void)animation{
CGRect topMovementFrame = self.topView.frame; //Set dummy frame to modify
CGRect bottomViewFrame = self.bottomview.frame;
topMovementFrame.origin.y = 0 - self.topView.frame.size.height; //modify frame's yAxis so that the frame sits above the screen.
bottomViewFrame.origin.y = self.view.frame.size.height; //modify frame's yAxis to the it will sit at the bottom of the screen.
[self.viewToLoadIn setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
//Animation
self.topView.frame = topMovementFrame; //Commit animations
self.bottomview.frame = bottomViewFrame;
self.backView.alpha = !self.backView.alpha;
self.backView.transform = CGAffineTransformMakeScale(100, 100);
self.viewToLoadIn.transform = CGAffineTransformMakeScale(2.0, 3.0);
*MAGIC*
} completion:^(BOOL finished) {
//Completion
//Clean up your views that you are done with here.
}];
}`
So then When they pressed the button I had setup this animation would happen.
Also at first I thought that the setup might contain a UIActionStyleSheet. which it still might but this is a pretty handy built in functionality. But the fact that you can interact with the screen lead me to think a custom view. It would be easier in my opinion.
I hope this helps you even if it just a little bit.
Take care ^^
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I am trying to implement an alert/notification bar that will appear at the bottom of the page, and when clicked will scroll up and cover the entire screen (just like Kayak or PageOnce apps show it). Here's how it looks right now (Have uploaded the images at below URLs):
Image showing alerts bar at the bottom
http://www.anony.ws/hLe
Alerts bar opened up
http://www.anony.ws/hLl
It works but not completely. One thing, the alert view is not able to cover the navigation bar (alert frame's origin y is 0 in the attached screenshot for opened up view). If I make the frame's y negative to go further up, the view goes behind the navigation bar. How can I make it work so that the alerts view covers the entire screen (including the navigation bar).
Here's what I have done:
In the "Member Center" view controller, on viewDidLoad, I am creating a new view (my AlertView), changing it's frame to show up at the bottom and then adding it as a subview to current view:
CGFloat alertBarHeight = 25;
CGRect frame = self.view.frame;
frame.origin.y = frame.size.height - alertBarHeight;
AlertsView *av = [[AlertsView alloc] initWithFrame:frame withController:self height:alertBarHeight]; // Its a custom init method that just stores a reference to the invoking controller
[self.view addSubview:av];
My show/hide code is in AlertsView.m and looks like this:
- (void) showOrHideAlerts:(id)sender
{
if (self.isOpen)
{
// Close the alerts view
[UIView animateWithDuration:0.4 delay:0 options:UIViewAnimationOptionCurveEaseOut
animations:^{
CGRect frame = self.frame;
frame.origin.y = self.invokingController.view.frame.size.height - self.barHeight;
self.frame = frame;
}
completion:^(BOOL finished)
{
self.isOpen = NO;
}];
}
else
{
// Show the alerts view
[UIView animateWithDuration:0.4 delay:0 options:UIViewAnimationOptionCurveEaseOut
animations:^{
CGRect frame = self.frame;
frame.origin.y = 0;// - [self.invokingController.navigationController navigationBar].frame.size.height;
//frame.origin.y = 20;
self.frame = frame;
}
completion:^(BOOL finished)
{
self.isOpen = YES;
}];
}
}
I feel that I am not implementing it correctly. Please guide me on what's the best way to implement such a feature.
Add your alert view to navigation controller view as below and not in the current view:
AlertsView *av = [[AlertsView alloc] initWithFrame:frame withController:self height:alertBarHeight]; // Its a custom init method that just stores a reference to the invoking controller
[self.navigationController.view addSubview:av];
You can Hide The navigation bar when alert view is Open And Again Show it when Alert View is Closed .
to hide :
[self.navigationController setNavigationBarHidden:YES animated:NO];
to Show:
self.navigationController setNavigationBarHidden:NO animated:NO];
Hope it helps.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have drawn shapes, such as circles, rectangles, and triangle in context..
Now i want to move, rotate and scale that drawn shape.
I'm not sure how you're doing your drawing, but it looks like you need to start from the beginning. If you've drawn something in a UIView using 'drawPath', you can animate the view with methods like animateWithDuration: animations: completion:. Here's an example that will move a view up the screen and then remove it from the view.
CGRect endFrame = myView.frame; // get the original frame
endFrame.origin.y += 200; // move y-origin of the frame by 200.
// In this case, the animation consists of changing myView's current frame to
//endFrame over the course of 0.3 seconds. When the animation is complete,
//myView is removed from the screen.
[UIView animateWithDuration:0.3
animations:^{
myView.frame = endFrame ;
}
completion:^ (BOOL finished) {
if (finished) {
[myView removeFromSuperview];
}
}];
To get an idea of what you're doing, the view programming guide in the apple documentation is very useful, particularly the section on animations, UIView animations.
I think this is a very basic question, but I am struggling with this one.
I have a screenshot (an UIImage) which I put into an UIView (called screenShotView in my sample below). I want to get rid of this screenShotView by gradually revealing what is behind this screenShotView. Right now my screenShotView SQUEEZES to the left, but I would like its FRAME to become less and less until the screenShotView is no longer seen (without Squeezing).
This is my code. If I did the same transformation with an UITextView (instead of an UIImage) it would work exactly how I would like it to behave (without transformation).
Perhaps I don't get the concept of framing UIImages?
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:10];
[screenShotView setFrame:CGRectMake(0, 0, 0, 480)];
[UIView commitAnimations];
And this is how it looks like in the middle of the animation:
And this is how I would like it to look like in the middle of the animation:
This is the code updated to Codo's suggestions (see below), with the result that I have no animation anymore. The blue screen simply pops up once the button is pressed. I guess that I am doing something wrong with adding the subviews -- the problem appears to be that no subviews are added and can therefore not disappear:
-(IBAction)showNextText
{
screenShotView = [[UIImageView alloc] initWithImage:[self screenshot]];
[screenShotView setFrame:CGRectMake(0, 0, 320, 480)];
[screenShotScrollView setFrame:CGRectMake(0, 0, 320, 480)];
[self.view addSubview:screenShotScrollView];
[screenShotScrollView addSubview:screenShotView];
screenShotScrollView.scrollEnabled = NO;
[self setUpNextText];
[self removeOldText];
}
-(void)setUpNextText
{
NSString* secondText = #"This is the second text shown if the user clicks next.";
textView.text = secondText;
textView.textColor = [UIColor redColor];
textView.backgroundColor = [UIColor blueColor];
}
-(IBAction)removeOldText{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:5];
[screenShotScrollView setFrame:CGRectMake(0,0,320,480)];
[UIView commitAnimations];
}
Answer to question
It's actually very simple: I've made a sample app to get the star wars(just calling it here) transition working. For simplicity I'll just call the two views firstView and secondView. firstView is shown (would be your screenshot) and secondView will slide in from the left. I've put a button on each view to animate the transition, which is wirde to doTransition. The important part is to set the sliding in view's properties clipsToBounds = YES and autoresizesSubviews = NO. That's it. I'll post some screenshots.
- (void)viewDidLoad
{
[super viewDidLoad];
secondView.frame = CGRectMake(0, 0, 0, 480);
secondView.clipsToBounds = YES;
secondView.autoresizesSubviews = NO;
[self.view addSubview:firstView];
[self.view addSubview:secondView];
}
- (IBAction)doTransition
{
[UIView animateWithDuration:1.0
animations:^{
self.secondView.frame = CGRectMake(0,
0,
320,
480);
}];
}
Research on page curl
I did some research on the page turn / curl effect. Mainly this is all present in iOS, with little effort you can create the iBook page turn effect, but it's accessing private methods and classes. I still encourage anyone to have a look at it, cause it might some day be opened.
Apple's iBooks Dynamic Page Curl - Demo App by Steven Troughton-Smith
Leaves - An App with a custom page curl by Tom Brow, tried, compiled and looks nice!
App Store-safe Page Curl animations - Article on Tom Brow's Leaves App which has been branched (twoPages) by the author Ole Begemann
Implementing iBooks page curling using a conical deformation algorithm - With a MacOS Demo App, very professional and advanced, though not an option for a quick shot still inspiring. Download the App!
The anatomy of a page curl - Mathematical approach
I guess you have to put your upper view into a UIScrollView. Then you set the content size to be the same as the size of the UIScrollView and disable scrolling.
Next you do your original animation (setFrame) on the UIScrollView.
Basically, you then use the UIScrollView to introduce a separate coordinate system for the inner view. When the outer view (the scroll view) is made smaller, it will not distort the inner view, but clip it.
CGRect fillRect = self.view.bounds;
leftImageView.clipsToBounds = YES;
leftImageView.contentMode = UIViewContentModeTopLeft;
leftImageView.frame = fillRect;
rightImageView.clipsToBounds = YES;
rightImageView.contentMode = UIViewContentModeTopRight;
rightImageView.frame = CGRectMake(fillRect.size.width, 0, 0, fillRect.size.height);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:3];
leftImageView.frame = CGRectMake(0, 0, 0, fillRect.size.height);
rightImageView.frame = fillRect;
[UIView commitAnimations];
Don't animate the frame but the center. See the documentation here.
Also, if you only need iOS 4 compatibility, use -animateWithDuration:animations:
[UIView animateWithDuration:10
animations:^{ screenShotView.center = CGPointMake(x, y) } ];
I'm not sure I fully understand how you want your view to disappear.
If it's supposed to become more and more transparent, use the following code (instead of setFrame):
[screenShotView setAlpha: 0.0f];
If it's supposed to become smaller and smaller (but keep its center), then try:
[screenShotView setFrame:CGRectMake(screenShotView.frame.x, screenShotView.frame,y, 0, 0)];
One simple question:
This is an example of an old fashion animation:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[base setTransform:rotate];
[base setCenter:newCenter];
[UIView commitAnimations];
this can be written like
[UIView animateWithDuration:0.5 animations:^{
[base setTransform:rotate];
[base setCenter:newCenter];
}];
is there any advantage in rewriting the animation using this new form?
There should be some kind of gain, or Apple would not make this new function.
What do you guys say?
Apple made the change not for performance, but because blocks are an easier way to express this kind of thing. Previously you'd have to use selectors to be triggered when an animation finished, etc.
So - why to use animateWithDuration: because blocks save time, make code cleaner, and are just generally very useful.
And why to use beginAnimation: because you want to support versions of iOS prior to 4.0, where that code isn't available. Apple still need to provide both methods because they need to remain backwards compatible - but the documentation strongly recommends you use the blocks version of methods where available and appropriate.
I think animateWithDuration is newer and look better. I use it more than beginAnimation. It is more clear code. beginAnimation use when you need compatible for iOS version less than 4.0.
But in some case, beginAnimation has more advantage, make easier when you write a function with a parameter animated. Example:
- (void)moveSomethingWithAnimated:(BOOL)animated {
// Do other task 1
if( animated ) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.2];
someView.frame = newFrame;
otherView.frame = newFrame;
}
if( animated ) {
[UIView commitAnimations];
}
// Do other task 2
}
Instead of:
- (void)moveSomethingWithAnimated:(BOOL)animated {
// Do other task 1
if( animated ) {
[UIView animateWithDuration:0.2 animations:^{
someView.frame = newFrame;
otherView.frame = newFrame;
}];
}
else {
// duplicate code, or you have to write another function for these two line bellow
someView.frame = newFrame;
otherView.frame = newFrame;
}
// Do other task 2
}