I have the code below in my viewcontroller.m:
panoView_ = [[GMSPanoramaView alloc] initWithFrame:CGRectMake(0, 0, 10, 25)];
self.view = panoView_;
[panoView_ moveNearCoordinate:CLLocationCoordinate2DMake(-33.732, 150.312)];
I want to create a little space at the bottom of the view to place a button in the storyboard but this isn't working as the map (street view) takes up the entire screen. Any advice?
If you want the button to appear below the map then use 2 views.one view (panoViewContainer) contains a panoView and second view (mainView - which is self.view) contains panoViewContainer and a button below panoViewContainer.
// Place panoViewContainer in mainView by keeping space for button at bottom,
self.panoViewContainer.frame = CGRectMake(0, 0, width, (height - spaceForButton));
[self.mainView addSubview:self.panoViewContainer];
self.panoViewContainer = panoView_;
// Place a button in mainView, below panoViewContainer.
[self.mainView addSubview:button];
Related
I want to insert an UIView between Navigation Bar and UIView (Underneath NavigationBar) to show network connectivity status.
Also View underneath Nav Bar should go downward to make a space for indicatorView.
My code:
indicatorView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, VIEW_WIDTH, 35)];
[self.view addSubview:indicatorView];
self.view.frame = CGRectMake(0, 35, VIEW_WIDTH, VIEW_HEIGHT - 35);
This inserts a view but whole window shift upwards and create a space at bottom of View. What's wrong?
I am currently in process of making a registration form on my app in Swift 3 / xcode and I first have 3 text fields showing with a continue button underneath, I want it so the user presses the continue button and the current stackview slides out of view and a new one slides in (similar to a segue with the storyboards
This will show first and then they press continue:
Then this stack view will show:
Could somebody please point me in the right direction of how to do this?
Thank you.
For your case, I'm not pretty sure of what is the purpose of using a stackView. I suggest to use UICollectionView (horizontal) instead (UIStackView does not scroll which is inappropriate for what are you trying to achieve), especially that the two views should be the same cell in your case. All you have to do is to check what's the current indexPath.row for determining what cell's components should look/behave.
Also, You can add target to the button to let the collectionView scrolls to the next cell if it's the first row, for the second row it should -for example- submit the form.
Hope it helped.
#Chad, if you want to use scrollable and easy solution you could try ScrollableStackView library. Here is the github page :
https://github.com/gurhub/ScrollableStackView
Here is some sample codes :
Swift
import ScrollableStackView
var scrollable = ScrollableStackView(frame: view.frame)
view.addSubview(scrollable)
// add your views with
let rectangle = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 55))
rectangle.backgroundColor = UIColor.blue
scrollable.stackView.addArrangedSubview(rectangle)
// ...
Objective-C
#import ScrollableStackView
ScrollableStackView *scrollable = [[ScrollableStackView alloc] initWithFrame:self.view.frame];
scrollable.stackView.distribution = UIStackViewDistributionFillProportionally;
scrollable.stackView.alignment = UIStackViewAlignmentCenter;
scrollable.stackView.axis = UILayoutConstraintAxisVertical;
[self.view addSubview:scrollable];
UIView *rectangle = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 55)];
[rectangle setBackgroundColor:[UIColor blueColor]];
// add your views with
[scrollable.stackView addArrangedSubview:rectangle];
// ...
Hope it helps.
I would like to display a small UIView with some text in the center of a UITableViewController when I call the showHud method.
- (void) showHud {
UIView *paintView=[[UIView alloc]initWithFrame:CGRectMake(150, 150, 120, 30)];
[paintView setBackgroundColor:[UIColor yellowColor]];
[self.view addSubview:paintView];
}
Actually the problem with this code is that the view doesn't stays on its place, when I scroll the tableview it goes up with cells. Is it possible to pin it somehow?
I don't think you can achieve that with a UITableViewController because the view property of such controller is a UITableView, so the content will always scroll with it.
You need to create a regular UIViewController and add a UITableView to that controller's main view. Then anything else you add to that main view, will stay in place as it is outside of the table view.
Try implementing scrollViewDidScroll delegate method and change the frame of paintView according to tableview offset.
eg:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGPoint offset = scrollView.contentOffset
[paintView setFrame:CGRectMake(150, 150+offset.y, 120, 30)];
}
But the best way would be to create a simple UIViewController.
You must use UItableViewController because of pullToRefresh controller?
UI could add a view to the window and position it to the very front:
UIView testView = [[UIIView alloc]initWithFrame:CGRectMake(10, [[UIScreen mainScreen]applicationFrame].size.height - 85 , 75, 75)]; [[[[[NSApplication sharedApplication] mainWindow] contentView] addSubview:testbox]; addSubview: testView]; testView.layer.zPosition = MAXFLOAT;
An UITableViewController is typically embedded in a "parent" view controller, like UINavigationController. Its UITableView will then have a superview, like UINavigationControllerWrapperView. Even if your table view controller is a root view controller, the table view's superview is UIWindow.
So you can safely assume that your table view always has a superview. Then add your UIView to this superview instead of the table itself:
//Note: frame should be different here as it's in the superview's coordinate system
UIView *paintView=[[UIView alloc]initWithFrame:CGRectMake(150, 150, 120, 30)];
[paintView setBackgroundColor:[UIColor yellowColor]];
[self.view.superview addSubview:paintView];
I have created a UIView in a storyboard. See here for more information. My issue is when the user "logs in" then I present a new view bringing it from the left side of a screen and the main view slides off to the left, like a push navigation, but all programmatically.
So I have decided to animate this "navigation" using the following code.
view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
view.backgroundColor = [UIColor whiteColor];
//add stuff to view
[view addSubview: label];
view.frame = CGRectMake(320, 0, 0, 480);
view.clipsToBounds = YES;
[self.view addSubview:view];
//show view
[UIView animateWithDuration:.5
animations:^{
self.view.frame = CGRectMake(0,0,0,480); //move self.view off left
view.frame = CGRectMake(0, 0, 320, 480); //move new view in place
}];
My view is being successfully displayed but the existing view, self.view is not going off the left side of the screen like I want it. It moves, but it doesn't take it's components with it... When I comment out //view.frame - CGRectMake(0,0,320,480); inside the animation, so I don't display the new view I get this in the simulator on login.
The white background of the view leaves the screen but the components do not. This causes an issue because when I put the two together it does not look like the "new view" is replacing the old view like a navigation push controller but instead sliding over it. Is there a way to move these components with the self.view when I move it off the screen
Thanks for the help!
I am not sure if you can move self.view. Even if it is possible, it's not a good idea...
Anyway your code
self.view.frame = CGRectMake(0,0,0,480);
doesn't slide the view. It scales the view into a zero-width rectangle, which explain why its subviews are still there. By default subviews are aligned to top-left corner of their superviews, and since self.view's top-left hasn't moved (still (0, 0)), they remain the same. The proper way to slide a view off the screen is:
self.view.frame = CGRectMake(-320,0,320,480); // width & height MUST remain unchanged
Still, this will NOT work, since you have made view a subview of self.view... which means this line:
view.frame = CGRectMake(0, 0, 320, 480);
will set view.frame relative to self.view which now has been slided off the screen! So they will be both gone. Another good reason why you shouldn't play with self.view.frame.
IMHO, you should create a view v1 as the main view, and v2 the view that appears when logged in. Make them both subviews of self.view, hide v2 behind v1 and when user logs in, slide v1 off the screen as described above. Or maybe put v1 to the right of v2, and slide them both (so v1 will be sliding out why v2 sliding in, similar to a navigation controller).
I want to change the existing view in a UIViewController to a new view. The new view contains the old view and a little banner view.
Doing this fairly simple change leaves me with a black view.
My code looks like this
UIView *existingView = self.view;
UIView *newView = [[UIView alloc] initWithFrame:existingView.frame];
UIView *bannerView = [[UIView alloc] initWithFrame:CGRectMake(0, (self.view.frame.size.height - 50), 320, 50)];
CGRect existingViewFrame = existingView.frame;
existingViewFrame.size.height -= 50;
existingView.frame = existingViewFrame;
[newView addSubview:existingView];
[newView addSubview:bannerView];
self.view = newView;
However when switch Tabs and come back to the view which changed the view is shown just like I want. I guess I need to set a flag or something to tell the controller to redraw it's (new) view.
Edit
I wrote an simple example for this problem. You can find it on GitHub: https://github.com/Oemera/ChangeView
You did not say where you do this. It may be that you need to save the original view's super view, then add the new view to that views subViews array. I'm betting that is the problem.