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
}
Related
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
I've tried creating two UIButtons programatically as described here. This works great but there doesn't seem to be a simple transition for expanding the UIButton on the left as seen in the Apps Store.
If you would like to animate the size of your button, you can use transforms or make the frame larger. Just set the new frame or transform, start the animation, and your button should animate to it's new size.
Assuming your button starts as 50 wide, 38 high and is at the 100,100 point of the screen:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.5];
yourButton.frame = CGRectMake(70, 100, 80, 38); // this makes the button 80 wide, expanding to the left
//here you can change other values, such as the background image and title.
[UIView commitAnimations];
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.
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.
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];