Animating the display of a View - iphone

I have added a button on a view(the view is of the same size as the button). When that button is clicked a new view has to be displayed. So in the button's event handler I have added the newview as a subview of the view on which the button is added, so that the newview gets displayed when the button is clicked. The thing here I need to do is, when I click on the button, the newview has to be invoked from top to bottom (it has to look like it slides down from the button's view). When the same button is clicked again, the newview has to scrollback(slide) and disappear. I know that I need to apply some animation stuff to get this effect. But I have no idea how to do this. Can you please help me giving some ideas.
Thanks in advance!!!

Well you can animate the size of your window to simulate the slide from top like this:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
myView.frame = CGRectMake(0, buttonHeight+buttonTop, myView.frame.size.width, viewTargetHeight);
[UIView commitAnimations];
Make sure you set the view height to 0 when you create it.
To scroll it back up just do the opposite
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
myView.frame = CGRectMake(0, buttonHeight+buttonTop, myView.frame.size.width, 0);
[UIView commitAnimations];
If you actually want your new view to slide you can try animating both the size and the position and you'll also probably need to clip your animated view with another view.

Related

Setting UIControl's frame changes view bounds but not where it can receive touches

I have a headerView which can expand and collapse when pressed. It's default state is collapsed.
I use the following code to expand the headerView.
if (!self.headerViewIsExpanded) {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[self.collapsedHeaderView removeFromSuperview];
self.headerView.frame = self.expandedHeaderView.frame;
[self.headerView addSubview:self.expandedHeaderView];
self.tableView.frame = CGRectMake(self.tableView.frame.origin.x, self.tableView.frame.origin.y + offset, self.tableView.frame.size.width, self.tableView.frame.size.height - offset);
[UIView commitAnimations];
self.headerViewIsExpanded = YES;
}
It correctly expands the view frame and diminishes the tableView frame. However, it fails to expand the touches received area of the original UIControl, so I can only collapse it by pressing where the original frame was.
How can I resolve this issue?
EDIT: Alternatively, I would accept an answer with a good explanation of why I cannot resolve the issue, or at least not resolve it safely.
EDIT 1: To be more clear, the headerView is NOT a tableView header view. It is just a view that sits on top of the table that happens to be called headerView. Both headerView and tableView are subviews of the main UIView that spans the available window.
You can try to overload layoutSubviews method. Inside you should use setFrame method for your headerView to define all view elements position.

Touch issue during UIView Animation

I am animating UIView when user touches on custom dropdown to show picker View from bottom side.UIView contains Pickerview...so when I change it's frame to move upwards.I get what I want, but pickerView doesn't recognize touch !(see screenshot below)
code is like this
CGRect pickerFrame=self.pickerSheet.frame;
CGRect viewFrame=self.view.frame;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:SHEET_ANIMATION_DURATION];
//change Frame of View containing UIPickerView
pickerFrame.origin.y=202+animatedDistance;
viewFrame.origin.y-=animatedDistance;//animated distance is value by which view needs to move upward.
[self.pickerSheet setFrame:pickerFrame];
[self.view setFrame:viewFrame];
[UIView commitAnimations];
screenshot
first of all, ++please**, stop using this animation declaration, and bedin use new, block animation:
[UIView animateWithDuration:SHEET_ANIMATION_DURATION
delay:0
options:nil
animations:^{
pickerFrame.origin.y=202+animatedDistance;
viewFrame.origin.y-=animatedDistance;
}
completion:^(BOO f){
//any actions after animation ended
}];
Second, I think your problem is somewhere else. May by, you implementing your touches or picker wrong.
Please start using the new , better animation block , but I think there is something missing in your code , you need to put the code below :
UIViewAnimationOptionAllowUserInteraction
Put this code in options in the new animation block , or find a way to put it in the old animation block

How to slide(push) controls down/up in a View?

I have a button which when pressed, should push the controls below it down and show textFields on the space freed. Basically, just changing the position of these controls in an animated way. Any ideas/tips on how to do that?
I tried the code in: How to Make a UITextField Move Up When Keyboard Is Present
But couldn't get it to work just changing the methods. Appreciate any useful information.
Thanks!
I think you have write code for that. If your controls below is a view (BottomView), when you press the button, change the frame of the BottomView, to make room for the textfield view. Now add the textField there. Write the code in a Animation block.
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.3f];
// bottomView.frame = (new frame)
// design a textfield in IB. make outlet.
// textField.frame = (new frame)
[UIView commitAnimations];

iphone - not full screen modal

At some part of my code I am using this line
[[self navigationController] pushViewController:myController animated:YES];
This works perfectly and pushes a view, coming from bottom, over the current one, covering the last one completely.
I am wondering if there's a way to make it cover just part of screen. Let's say, just the half bottom of the screen...
Is it possible? I have tried to change the controller's view frame but the size kept coming full screen.
thanks.
Instead of using a new view controller modally, you could add a new subview to your existing view, using the same view controller.
You can do the "slide in" animation with something like:
[self.view addSubview: newView];
CGRect endFrame = newView.frame; // destination for "slide in" animation
CGRect startFrame = endFrame; // offscreen source
// new view starts off bottom of screen
startFrame.origin.y += self.view.frame.size.height;
self.newImageView.frame = startFrame;
// start the slide up animation
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.3];
newView.frame = endFrame; // slide in
[UIView commitAnimations];
You can do it in a limited fashion with a modal view controller. Check out the presentation options available under UIModalPresentationStyle in the apple docs.
You will need to be on iOS 3.2 or above to do a modal view controller.

Making a UIView "disappear" behind another tabbar

I'm using the following code to make a small view disappear at the bottom of the screen:
int y_dest = self.application.windows.frame.size.height;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.33f];
[UIView setAnimationDelegate:self];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(closeAnimationDidStop:finished:context:)];
self.view.frame = CGRectMake(0, y_dest, self.view.frame.size.width, self.view.frame.size.height);
[UIView commitAnimations];
This works perfectly when the view is at the bottom of the screen but now I have to add it to the window above a TabBar meaning that the view is now animated over the top of the tabbar rather than behind it. Is there any way to have the view "disappear" behind the tabbar?
I've tried a combination of things so far including creating a "mask" view of the same size as the animated view and placing that in the window but for some reason that view did not appear at all. I also tried using insertSubview:belowSubview which made no difference. I'm sure I must be missing something here.
Thanks in advance!enter code here
Is it:
[self bringSubviewToFront:yourView] you are looking for?