scale a UITableView to fullscreen from inside a UIScrollView - iphone

Having failed in trying to puzzle together different sources to any form of coherent approach or concept I turn, once again to the learned people of StackOverflow. My problem is quite specific and maybe that's why I'm having trouble finding information that fits or maybe I just suck at searching. Either way, here goes.
I am building an app which has a UIScrollView populated with UIViews which in turn are populated with UITableViews. I have paging and everything set up and working properly. Basically, I am trying to mirror the functionality of Safari's (mobile) tab behaviour, or (even closer to what I'm trying to achieve) Tweetdeck's main page. I couldn't post an image but if you click on the link below you'll see what I mean.
http://www.redmondpie.com/wp-content/uploads/2009/07/TweetdeckIphone04.jpg
The reason for the UITableViews are inside UIViews is that this was the only way I could figure out to make the tableViews have a space between them, instead of being right next to each other. I tried setting the size of the tableViews and the inset of the scrollView, among many things but the tableviews always ended up filling the entire scrollView. In any case, that is a separate issue, possibly
As I click on a tableView/UIView inside the scrollView I want that tableView/UIView to scale up and fill the entire screen (minus tabBar and navigationBar), and then I should be able to scale it back down by pressing the back button on the navigationBar.
Any information or nudges in the right direction is greatly appreciated.

I am doing something similar in my app:
-(void)displayPage:(int)targetedPage {
...
[UIView beginAnimations:#"MultiViewAnimate" context:nil];
[UIView setAnimationDuration:0.3];
//animate the frame
//targetedPage is the index (table view) that should be displayed
[(UITableView *)[tableViews objectAtIndex:targetedPage] setFrame:CGRectMake(0, 0, 320, 372)];
[(UITableView *)[tableViews objectAtIndex:targetedPage] setUserInteractionEnabled:YES];
...
[UIView commitAnimations];
}
-(void)displayMultiView:(id)sender {
...
[UIView beginAnimations:#"MultiViewAnimate" context:nil];
[UIView setAnimationDuration:0.3];
//animate the frame
//targetedPage is the index (table view) that I was previously looking at full screen
[(UITableView *)[tableViews objectAtIndex:targetedPage] setFrame:CGRectMake(60, 70, 200, 232)];
[(UITableView *)[tableViews objectAtIndex:targetedPage] setUserInteractionEnabled:NO];
...
[UIView commitAnimations];
}
In this code tableViews is an array of all the UITableViews that the scrollView contains.
I am doing a little more than this because I am taking a screenshot of my view and using a UIImageView for the scaled view and then animating back out to the respective UIWebView. One advantage to that approach is that I can just attach a UITapGestureRecognizer to the UIImageView and not have to mess with turning off userInteraction on the UITableView.

Related

Flip animation between two UIViews on a UIViewController

I have two UIViews on my view controller. I wanted to flip between the two views on user touch. Everything is fine except the animation I tried two methods, first was:
[UIView transitionFromView:frontView toView:backView
duration:01.0 options:UIViewAnimationOptionTransitionFlipFromRight
completion:NULL];
This was animating the view but actually animating the whole view controller's view, while I wanted only the portion where my views are, which is about 320x200 in the centre of the screen.
Then I tried the other option, which is:
[UIView animateWithDuration:1.0 delay:0.0
options:UIViewAnimationOptionTransitionFlipFromRight
animations:^{
[frontView removeFromSuperview];
[self.view addSubview:backView];
} completion:nil];
But this is not animating the views at all. Just switching the views instantly without any animation. Can anyone please help me in understanding where I am wrong or need to change. Thanks very much for your time and consideration.
Awhile after I posted my question I found a great answer for this query which you guys can look at :
How to flip an individual UIView (without flipping the parent view)
The trick is to use third UIView as container view and then adding the views, which needs to be animated, as subviews on it. That does the trick in my case. Remember that I am using the first method that I mentioned in my question. Thanks everyone for your time.

Issue with animation of UITextView in a UIView

I have a setup in which I have my main UIView, within this I display another UIView which appears to slide & expand until fully in view. Within this new view I have a UITextView, however when I run the animation to make the UIView appear it doesn't seem to apply the animation to the UITextView. The effect of this is that the UITextView just appears in its final position straight away, the rest of the UIView then slides into place. Is there a way to make the animation apply to the widgets inside the view as well?
Here is the code I'm using at the moment.
[self.view addSubview:innerView];
[innerView setFrame:CGRectMake(29.5,127,261,0)];
[textView setFrame:CGRectMake(20,20,221,0)];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:5.0];
[innerView setFrame:CGRectMake(29.5,127,261,275)];
[textView setFrame:CGRectMake(20,128,221,129)];
[UIView commitAnimations];
Please can someone help me out? I've been playing around with this problem for a long time now with no luck at all.
I had similar behavior in one of my apps. It was due to the autoresizingMask on a UITextView. Also make sure your top UIView does not have autoresizesSubviews option enable as it will influence the behavior of your UITextView on animation.

UIView loses background when animated up

I am working on an iOS app and am having trouble with a really tall UIView (2400px tall). The UIView contains a really long form that's been broken down into 5 parts. As the user completes one part of the form, I would like to slide the UIView up to reveal the next part. I present the UIView modally.
The problem that I am having is that when I slide up the UIView, the background slides up along with the objects in the first section and the next section is left with a clear background. The code I use to slide the UIView is:
- (IBAction)slideUp {
// Slide the view up the screen to reveal the next section
CGRect frame = self.view.frame;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.75];
frame.origin.y = -480;
self.view.frame = frame;
[UIView commitAnimations];
}
All of the objects in the really tall UIView slide up fine, I'm just losing my background color. Any idea why?
Thanks!
Is your background being rendered by some sort of "background view" that's sized to fit the screen?
In any case, you should probably use a UIScrollView with scrolling disabled instead of a really long UIView. You can then simply animate the contentOffset property to scroll the controls up, but the scrollview itself can simply be screen-sized.
Instead of using self.view.frame, i would highly recommend you create an IBOutlet for the really long view so that the code looks like self.longView.frame.
This will help making it clear which views you are working with.
Right now i am betting that you are animating the wrong view.

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

Get a image from a uiview

I want to perform a shrink animation on a UITableVIew. I experimented a bit and found out that the animation runs much faster when I shrink a UIImageView with an image of the current state of the tableview instead of shrinking the table view itself.
I grabbed the image in a method in my main viewcontroller prior to the animation:
UIGraphicsBeginImageContext(mainTableView.bounds.size);
[resizeContainer.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Works like a charm, at least almost. On very rare occasions I get weird graphic glitches, where the UIImage starts to overlap a toolbar that lies underneath it.
I just want to make sure that I am getting the image in the right way. I am laking the necessary understand of GraphicContexts to be sure about it.
To cut a long story short, is my code correct?
Thx
In what way did you animate the table? I haven't had problems with it animating slowly. Here is an example of what I did when I had to resize my table:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[mainTableView setFrame:CGRectMake(0,43,320,176)];
[UIView commitAnimations];
The reason I would suggest not just taking a screenshot but actually animating the table is because the animation could possibly start as the table is still scrolling. For instance the user just happened to flick the table as it started animating then you would have a jump to the new state when you fade out the "screen shot" that you took.
It went away with iOS 4.0. So I guess it was a bug.