How to move multiple UIViews Side-by-Side just like an twitter application working in iPad. With full of effects animation and rotations.
You should take a look at the UIScrollView with paging enabled.
Make all your views and put them next to one another inside a UIScrollView. i.e.
// Get your views
MyView *v1 = [[[MyView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)] autorelease];
MyView *v2 = [[[MyView alloc] initWithFrame:CGRectMake(320, 0, 320, 480)] autorelease];
MyView *v3 = [[[MyView alloc] initWithFrame:CGRectMake(640, 0, 320, 480)] autorelease];
// Make the UIScrollView
UIScrollView *scroll = [[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)] autorelease];
[scroll setPagingEnabled:YES];
[[scroll addSubview:v1];
[[scroll addSubview:v2];
[[scroll addSubview:v3];
[scroll setContentSize:CGSizeMake(960, 480)];
// add the scroll view to your view
[[self view] addSubview:scroll];
Now, the three views (v1, v2 and v3) are next to each other in a scroll view whose content is much wider the view. With paging enabled, they will scroll left and right but won't stop halfway through a view.
Take a look at view animations:
http://www.switchonthecode.com/tutorials/creating-basic-animations-on-iphone
Related
I have added few UI components using Storyboard (UILabel, UIImageView). I am trying to put UIScrollView in this view, below all other elements:
Here is my code right at the end of -viewWillAppear method (code from my View Controller):
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
scroll.contentSize = CGSizeMake(320, 480);
scroll.showsVerticalScrollIndicator = YES;
[self.view addSubview:scroll];
[self.view sendSubviewToBack:scroll];
The reason why I need a UIScrollView is large amount of text in detailsLabel - I'm attaching code I use for handling this label programatically:
detailsLabel.text = #"Some long text taken from databse";
[detailsLabel sizeToFit];
detailsLabel.numberOfLines = 0;
detailsLabel.lineBreakMode = UILineBreakModeWordWrap;
What I am doing wrong? How do I put UIScrollView below all other elements of my main view?
Try this:
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
scroll.contentSize = CGSizeMake(320, 480);
scroll.showsVerticalScrollIndicator = YES;
[self.view insertSubview:scroll atIndex:0];
...
[self.view insertSubview:detailsLabel atIndex:1];
Put your code in ViewDidLoad . Then add the labels after you have added the UIScrollView to the self.View in the ViewDidLoad itself. So by default the UIScrollView would be added on the self.View and then your label. Now you can either add the label on the scrollview or onto the self.view .
I've followed the instructions in this answer and it worked great: I've changed the Custom Class in Identity Inspector from UIView to UIScrollView and added this line to my -viewDidLoad in the View Controller file:
[(UIScrollView *)self.view setContentSize:CGSizeMake(320, 700)];
Option One:
Declare detailsLabel in .h:
IBOutlet UILabel * detailsLabel; // MAP IT WITH NIB or STORYBOARD
give it property and Synthesise in .m.
here in viewDidLoad declare:
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
scroll.contentSize = CGSizeMake(320, 480);
scroll.showsVerticalScrollIndicator = YES;
[self.view addSubview:scroll];
[self.view sendSubviewToBack:scroll];
[scroll addSubview:detailsLabel];
// IT SHOULD WORK.
Option two:
If you have large amount of text to display, then you can also use UITextView, it has inbuilt scrollview. And you can also set its text edit property.
- (void)viewDidLoad{
UIView *baseView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[self.view addSubview:baseView];
// Displays UIImageView
UIImageView *myImage = [[UIImageView alloc]
initWithImage:[UIImage imageNamed:#"ka1_046.png"]];
myImage.frame = CGRectMake(0, 0, 320, 460);
[baseView addSubview:myImage];
// create the UIToolbar at the bottom of the view controller
toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 425, 320, 40)];
toolbar.barStyle = UIBarStyleBlackOpaque;
[baseView addSubview:toolbar];
How can i make Main VC's UIToolbar which has no navigation controller and no tabbarcontroller global for all VC's
There are several ways,
First: you could instead of presenting the new viewcontrollers, you could just add them to the self.view and minimize their size to fit the view controller minus the tabbar
Second: you could share the instance of the tab bar in some global class, such as app delegate, just create the tab bar in the app delegate and add a property around it, so that other VC can access it, and then at each viewDidLoad of a new VC you would add it
Is it possible to create a side sliding tabs (like the menu in WP7; I'm not sure what the correct term is) for iPhone/iPad applications? I haven't implemented any code yet, right now I'm assuming that it could probably be done with multiple vertical UIScrollViews within a horizontal UIScrollView.
I've seen this kind of menu in iPad applications (Discovr Music/Movies), and would like to implement it in iPhone if it is possible. Also, is this kind of menu against any of Apple's UX policies?
Thanks!
This is possible and you can do it.
For example:
UIView *wrapper = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 640, 460)];
UIView *subView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
[wrapper addSubview:subView1];
UIView *subView2 = [[UIView alloc] initWithFrame:CGRectMake(320, 0, 320, 460)];
[wrapper addSubview:subView2];
[scrollView setContentSize:wrapper.frame.size];
[scrollView setPagingEnabled:YES]; //Here's what you want to do!
[scrollView addSubview:wrapper];
Didn't test the code, but it should work.
Important is to add Subview to the ScrollView. (It would also work if you don't use a wrapper, but I often use it, because of the size.)
Dealing with this issue for last so many days when button is pressed on the Mainviewcontroller it plays audiofile as well as displays View with UIToolbar at the bottom of the View.
UIView has UIImage and UIText
My issue is that when View is loaded it shows gap between status bar and the loaded view and when infobutton is pressed from the UIToolbar on the view it presents Modalviewcontroller and when this Modalviewcontroller is dismissed back to the View it shows same gap between the status bar and the View.
- (void)displayviewsAction:(id)sender
{
self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]autorelease];
self.view.superview.frame = CGRectMake(0, 0, 320, 480);
PageOneViewController *viewController = [[[PageOneViewController alloc] init]autorelease];
[self.view addSubview:viewController.view];
[self.view addSubview:toolbar];
}
Please anyone knows how to fix this issue. Appreciate your help.
Thanks
After struggling for 2 days got the solution for my problem. It was very simple.
I made these changes
- (void)displayviewsAction:(id)sender
{
//self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]autorelease];
//self.view.superview.frame = CGRectMake(0, 0, 320, 480);
PageOneViewController *viewController = [[[PageOneViewController alloc] init]autorelease];
viewController.view.frame = CGRectMake(0, 0, 320, 480);
[self.view addSubview:viewController.view];
[self.view addSubview:toolbar];
}
Now there is no gap. It is working fine.
I have created a UIView through code and want to add some images and description on that view.For that purpose i wished to add a scroll view so that we can user can scroll down to see the images and description.Can anyone help me how to add a scroll view above a UIView through code.Thanks in advance.
Hi try this:-
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
scrollView.backgroundColor=[UIColor clearColor];
scrollView.showsHorizontalScrollIndicator = NO;
[scrollView setDelegate:self];
[scrollView setShowsVerticalScrollIndicator:NO];
[scrollView setShowsHorizontalScrollIndicator:NO];
[[self view] addSubview:scrollView];
Now set the content size of scroll view:-
scrollView.contentSize = CGSizeMake(320, 600);//put values according to your requirements.
UIScrollView *newView = [[UIScrollView alloc] initWithFrame:scrollFrame];
[newView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
[newView setDelegate:self];
[newView setBackgroundColor:backgroundColor];
[newView setPagingEnabled:YES];
[newView setShowsVerticalScrollIndicator:NO];
[newView setShowsHorizontalScrollIndicator:NO];
[[self view] addSubview:newView];
you can set Frame In place of scrollFrame.
cheers
Actually you probably don't want to create a UIView, you should create a UIScrollView then add the images and that as subviews of the UIScrollView. Then you'll have everything scrolling. You'll then set up the UIScrollView the way you want it to be.