I have created XIB file in freeform size because I need many controls to add. I have done it but when I push my view controller, it doesn't have automatic scrollbar on iPhone display and my view gets cropped! How to get my full view displayed on iPhone?
I have set view frame on view load but that doesn't make any difference!
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view setFrame:CGRectMake(0, 0, 320, 600)];
}
Following looks like cycling between view and scrollview worked for me! Not a good solution though!
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect frame = CGRectMake(0,0,320,600);
[self.view setFrame:frame];
self.scrollview = [[UIScrollView alloc] initWithFrame:frame];
[self.scrollview setBackgroundColor:[UIColor blackColor]];
[self.scrollview addSubview:self.view];
self.scrollview.contentSize = frame.size;
self.view = self.scrollview;
}
Thanks.
You should take a look at UIScrollView. Within the UIScrollView add a UIView for your content. You then need to set the content size of the UIScrollView to enable scrolling.
Example:
CGRect frame = CGRectMake(0,0,320,600);
UIView *subView = [[UIView alloc] initWithFrame:frame];
// Add objects to view
[self.scrollView addSubview:subView];
self.scrollView.contentSize = frame.size;
Hope this helps....
You have to take different approach for this case.
You need to add a UIScrollView to your controller's view - make it take the whole screen and then inside the scroll view you can add as much content as you wish - this way your form will be scrollable and the user can go up and down to see all the controls inside the form
Related
I am new in iphone development.. I have added the scrollview in my app and added 10 buttons graphically inside the scrollview. but when I run the scrollview is not scrolling
my code is as follow
- (void)viewDidLoad
{
[super viewDidLoad];
[scrollview setContentSize:CGSizeMake(1500,50)];
[scrollview setBackgroundColor:[UIColor blackColor]];
[self.view addSubview:scrollview];
}
It looks like you are taking scrollview in xib. So, you need to remove [self.view addSubview:scrollview]; from your code and you can directly set properties of that scrollview in xib except setContentSize(that you need to set in .m file).
Or if you want to create scrollView manually, remove from xib and use this:
UIScrollView * content = [[UIScrollView alloc] initWithFrame:self.view.bounds];
[content setContentSize:CGSizeMake(width, height)];
//Here you can add those buttons to content view
[self.view addSubView:content];
In my split view application it is not possible to add search bar to the rootView of the split view
So i added search bar dynamically at the tableHeaderView of the ui table view as folows
searchBar = [[UISearchBar alloc] init];
searchBar.frame=CGRectMake(0, self.tableView.frame.origin.y, self.tableView.frame.size.width, 44);
[searchBar sizeToFit];
self.tableView.tableHeaderView = searchBar;
When Scroll down: iThe tableHeaderView also scrolls down so search bar also scrolls
When Scroll top: The tableHeaderView also scrolls top so search bar also scrolls
I implemented code as follows to resolve this issue this helps only when scrolls down but when we scrolls the table view to topside it again move with the table view
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGRect rect = self.tableView.tableHeaderView.frame;
rect.origin.y = MIN(0, self.tableView.contentOffset.y);
self.tableView.tableHeaderView.frame = rect;
}
I need to stick the tableHeaderView/ Search bar at the top of the view always
How to do this
You can add tabBar separate with tableView
mySearchBar = [[UISearchBar alloc] init];
[mySearchBar setHidden:NO];
mySearchBar.placeholder = #"Search item here";
mySearchBar.tintColor = [UIColor darkGrayColor];
mySearchBar.frame = CGRectMake(0, 0, 320, 44);
mySearchBar.delegate = self;
[mySearchBar sizeToFit];
[mySearchBar setAutocapitalizationType:UITextAutocapitalizationTypeNone];
[self.view addSubview:mySearchBar];
And tableView
UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 44, 320, 436)];
[self.view addSubview:tableView];
If You want to add in xib then
Put your searchBar in separate view and put that view above the table view. That means it stays constant.
I'm sure this has been answered before, but assuming you're using UITableViewController, you can make the view property be anything you want. So one approach would be to set up a container view with your search bar at the top and the table below it and make view be this container. By default, tableView returns view, so another detail you'd need to take care of is overriding the tableView property to return the actual table view (that you've stored in an ivar). The code might look something like this:
#synthesize tableView = _tableView;
- (void)loadView
{
[super loadView];
_tableView = [super tableView];
// Container for both the table view and search bar
UIView *container = [[UIView alloc] initWithFrame:self.tableView.frame];
// Search bar
UIView *searchBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 50)];
// Reposition the table view below the search bar
CGRect tableViewFrame = container.bounds;
tableViewFrame.size.height = tableViewFrame.size.height - searchBar.frame.size.height;
tableViewFrame.origin.y = searchBar.frame.size.height + 1;
self.tableView.frame = tableViewFrame;
// Reorganize the view heirarchy
[self.tableView.superview addSubview:container];
[container addSubview:self.tableView];
[container addSubview:searchBar];
self.view = container;
}
I have created a UIScrollView and am now trying to place a UIButton over the scroll view. However when I build and run the application the scroll view still works fine but I cannot see the UIButton.
I link the UIButton IBOutlet inside the interface builder.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
scrollView.backgroundColor = [UIColor blackColor];
scrollView.delegate = self;
scrollView.bounces = NO;
backgroundImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"auckland-300.jpg"]];
image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"249a-134206f1d00-1342071f5d9.ImgPlayerAUCKLAND.png"]];
// Note here you should size the container view appropriately and layout backgroundImage and image accordingly.
containerView = [[UIView alloc] initWithFrame:CGRectMake(0,0,601,601)];
playButton = [[UIButton alloc] init]; //test button cannot see it.
[containerView addSubview:backgroundImage];
[containerView addSubview:image];
scrollView.contentSize = containerView.frame.size;
[scrollView addSubview:containerView];
scrollView.minimumZoomScale = 0.5;
scrollView.maximumZoomScale = 31.0;
[scrollView setZoomScale:scrollView.minimumZoomScale];
self.view = scrollView;
}
Any help would be appreciated
Everything seems ok. But I think the reason you are not able to see the button playButton is because you are not adding it to the view itself.
Dont you need to do this ? [containerView addSubview:playButton];
To help you out, here's what I do for debugging -
UIView implements a useful description method. In addition, it
implements a recursiveDescription method that you can call to get a
summary of an entire view hierarchy.
NSLog(#"%#", [controller.view recursiveDescription]);
The button is probably in the nib that you linked the controllers view to, right? By assigning the scrollview to the view, you remove the view from
The nib from the controller, that's why you can't see te button or press it.
You can either place the button in the scrollview or you add both scrollView and thenthe playButton as subviews of self.view.
Maybe you want to rethink your design tho.
Placing a button over a scrollview doesn't really seem like good practice to me.
I was about to implement a table view behavior like the one used in a certain part of the twitter app for iPhone, precisely I'm talking about the tableview shown when, in a geolocalized tweet, I tap on the location displayed under the tweet. . .here's some pictures just to give it a look:
as you can see the table view has a background beneath (actually the map), but it is not just a background UIView (or Mapview) because the table view pulls it up and down with herself if the scrolling is about to "bounce". . .and it is certainly not a section header/footer, because the table floats on it. . .so, do you have any ideas on how to implement that table view? Could it be a webview?
edit: I found a solution and posted it down
just add the tableview and the mapview to a scrollview and you should be all set.
//CREATE THE SCROLL VIEW
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 300)];
scrollView.delegate = self;
scrollView.backgroundColor = [UIColor grayColor];
scrollView.contentSize = CGSizeMake(320, 650);
//ADDING TABLE VIEW
CGRect cgRct = CGRectMake(0, 0, 320, 600);
tblSimpleTable = [[UITableView alloc] initWithFrame:cgRct style:UITableViewStyleGrouped];
tblSimpleTable.delegate = self;
tblSimpleTable.dataSource = self;
[scrollView addSubview:tblSimpleTable];
//ADDING MAP VIEW
myMap = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
myMap.delegate = self;
[scrollView addSubview:myMap];
self.view = scrollView;
Maybe you can use UIView animations.
You add a mapview at the same height as your table view but with its alpha set to 0 in interface builder.
After that you can do as follow in your IBAction method:
[UIView beginAnimations:#"displayMapView" context:nil];
[UIView setAnimationDuration:0.3];
mapview.alpha = 1;
CGRect tableviewFrame = tableview.frame;
tableview.origin.y += 200; // Height of your map view
tableview.frame = tableviewFrame;
[UIView commitAnimations];
This should do it !
Or you can try somthing like this in your (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath:
IWebView* webView = [[UISynchedWebView alloc] initWithFrame:
CGRectMake(0, 0, cell.bounds.size.width, cell.bounds.size.height)];
webView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
webView.tag = 1001;
webView.userInteractionEnabled = NO;
webView.delegate = self;
[cell addSubview:webView];
And load a Google Maps request or maybe put directly your mapview in your cell, haven't tried that.
Take a look at three20 library.
http://three20.info
and download source code from github at https://github.com/facebook/three20
In this framework there is a class named TTTableViewController that implement TTTableViewDragRefreshDelegate.
More, there an example application TTTwitter that use this class!
You can start from that and subclass to implement all features you need!
Ok I just figured it out. . .it was easy as hell. . .and was all about playing with the tableview first row, that has to be hidden to show the underlaying image, and the scrollview delegate that has to drag down with the tableview the underlying image when the dragging direction is down. . .here is the xcode project for you to give it a try :)
http://cl.ly/9bje
I noticed that Expedia app ( http://a5.mzstatic.com/us/r1000/027/Purple/4c/f4/6c/mzl.wcipbyyg.320x480-75.jpg) has a customized sectionIndex for UITableView on hotels list. (image attached)
I'm figuring that it could be a custom view, maybe with a vertical UISlider but, as I know, UISlider cannot recognize touch events on slides but just dragging ones.
So, how they do that ? A vertical sequence of buttons ? But, in this case, how to recognize dragging events ?
I would like to replicate that control but I need some hints ;)
thanks
There are more ways how to achieve the effect. Assuming you have a self.view initialized from a nib file and it's ordinary UIView, you can put this code into viewDidLoad:
- (void)viewDidLoad
{
CGRect tvFrame = self.view.frame;
tvFrame.origin = CGPointZero;
UITableView* tv = [[UITableView alloc] initWithFrame:self.view.frame];
tv.delegate = self;
tv.dataSource = self;
tv.showsVerticalScrollIndicator = NO;
[self.view addSubview:tv];
CGRect svFrame = CGRectMake(290, 10, 30, 400);
UIScrollView* sv = [[UIScrollView alloc] initWithFrame:svFrame];
sv.contentSize = CGSizeMake(10, 780);
sv.showsVerticalScrollIndicator = NO;
sv.bounces = YES;
CGRect vFrame = CGRectMake(10, 380, 10, 20);
UIView* v = [[UIView alloc] initWithFrame:vFrame];
v.backgroundColor = [UIColor blueColor];
[sv addSubview:v];
[self.view addSubview:sv];
[super viewDidLoad];
}
This will create a table with a narrow scroll view with a blue rectangle over the table. Now you can scroll both scroll views (the table is also a scroll view) independently.
Then you will have to setup delegates and receive scroll events via UIScrollViewDelegate. When one of the scroll views starts dragging, you have to start setting offset of the other scroll view.