How do I make a UIPickerView in a UIActionSheet - iphone

Just want to know how I would make a UIPickerView in a UIActionSheet with a simple array.
Ok well I actually found out how to put it into an action sheet but I like your way better because it applies more to my app, thanks, but I want to also know how put the options into the UIPickerView, I am just hung up on that part of that. I already have an array with the colors: red, green, blue, yellow, black, etc in it but I want to know how to put that into the pickerview if I have already used initwithframe:? Please anyone help I know it is a stupid question but I'm racking my head on my $$$$$$ Macbook.

You don't want to do that. Instead, create your UIPickerView in Interface Builder and connect it to an Outlet in your view controller. Add it as a subview of your main view and set its frame coordinates so that it is offscreen just below the bottom edge, x=0, y=480.
Then, when you want to display the picker, animate it onto the screen with something like:
[UIView beginAnimations:nil context:NULL];
[colorPicker setFrame:CGRectMake(0.0f, 416.0f, 320.0f, 216.0f)];
[UIView commitAnimations];
And then hide it when you're done picking with this:
[UIView beginAnimations:nil context:NULL];
[colorPicker setFrame:CGRectMake(0.0f, 480.0f, 320.0f, 216.0f)];
[UIView commitAnimations];
This will cause your picker to slide up from the bottom animated and slide back down when you're done.
I don't think adding a picker to a UIActionSheet, if it's even possible, is advisable.

Related

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.

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
}

scale a UITableView to fullscreen from inside a UIScrollView

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.

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.

UITableViewCell Custom Drawing and Animating when Entering Edit/Reorder Mode

I am trying to do something very similar to this post. Starting with Atebits Fast Scrolling in Tweetie post I have a UITableView subclass that does all of it's drawing in the drawRect: method of it's contentView. This works perfectly and is super fast. What I am trying to do now is animate the transition from editing to not-editing.
An example of what I am trying to achieve would be a situation with some text right aligned in the cell. When entering edit mode, the contentView shifts right to allow room for the editing control but the text shifts offscreen on the right as well. If I simply call [contentView setNeedsDisplay] in layoutSubviews I can readjust the right aligned text but it just jumps to it's new position.
How can I get the transition to animate?
Your layoutSubviews should look like this:
-(void)layoutSubviews {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
/* Change offsets here. */
[UIView commitAnimations];
}
You may also need to add to applicationDidFinishLaunching:
[UIView setAnimationsEnabled:YES];