I have a problem trying to relocate a UILabel when loading a View. I can move the label if I run this code
lTarget.frame = CGRectOffset(lTarget.frame, 0.0f, -75.0f);
from for example a button action, it works properly. But where should I put this code if I want it to be called on the view load?, I tried viewDidLoad and viewWillAppear but this doesn't work.
I need to relocate this label because I want a different layout for the 3.5 inch screen.
Any idea?
If you are using a xib or storyboard with Autolayout enabled, it will cause your view size and position to be recalculated between the calls to viewWillAppear: and viewDidAppear:.
You should be able to move your code to viewDidAppear: or turn off Autolayout.
Related
I have an app that is designed to start up in Landscape mode, this all works fine. I add an imageview to cover the screen and then add a scrollview halfway down. Again all works fine.
I then add a series of uiimageviews again all fine. I notice if i try to click the far right image there is no response but the other images preceding this work fine. With lots of digging around I discovered the viewcontroller keep portrait coordinates. I have a tabbar at the bottom when I click to go to another view and then go back to the main view the far right uiimageview not works. Has anyone seen this before? I am guessing the view is redrawing itself when it comes back?
You should use .bounds property instead of the .frame property of the view.
Bounds honor the UIVIew's coordinate system.
It's well explained in this answer: https://stackoverflow.com/a/8181113/402223
See this article which answered my question here
- (void)viewDidLayoutSubviews
{
// fix for iOS7 bug in UITabBarController
self.selectedViewController.view.superview.frame = self.view.bounds;
}
note don't add it to viewdidload method.
Thanks Martijn you put me on the right track.
I'm failrly new to LibGDX and I'm running into a problem.
I'm building a classically styled RPG/Adventure game in which I'm using a TiledMap(-Renderer) to create the map. I've followed different tutorials but can't get it to work. (last one was DPG's: Full working example link)
What I need, is a column of buttons on the right side of the screen (implemented that through ImageButtons). One of these buttons lead to a settings-kind of screen and another one should lead to the game map. Under a ClickListener of the button I've added DPK's code of
MapHelper map = new MapHelper();
map.setPackerDirectory("data/packer");
map.loadMap("data/world/level1/level.tmx");
map.prepareCamera((int)stage.getWidth(), (int)stage.getHeight());
map.getCamera().update();
map.render();
The MapHelper class is an exact copy of dpk's, only change above is the setting of the width and height of the camera. Any suggestion what I'm doing wrong here?
I don't think you want to invoke map.render() in the ClickListener callback. That would mean the map is only rendered when you click, and then not re-rendered (generally everything gets re-rendered on every screen re-fresh).
I think you need to track the map in your application class, and in the ClickListener callback you need to set a flag or somehow "enable" the map (perhaps setting it to something other than null). Then in the application's render() method you can check to see if the map should be rendered or not, and render it if so.
Specifically, move the calls to prepareCamera, getCamera and render out of the ClickListener.
I have this a simple question: How do I resize a UIViewController's view from a custom UINavigationController, since it's not working to simply set it's frame.
I have tried to, in my UIViewControllercategory, override setFrame of all UIViews, which didn't go well...
In a tableViewController I know I can set the tableview's contentInset, but that doesn't really help me here.
I think you can add another view to your UIViewController 's view's subviews. Then change the frame of this internal view is easy.
Hello stackoverflow fellows!
Please consider an UI workflow in iOS:
One main viewcontroller and several other viewcontrollers branching out from there:
mainviewcontroller
+-viewcontroller 1
+-viewcontroller 2
+-viewcontroller 3
etc.
I would like to be able to switch and switch back from the main viewcontroller to one of the other viewcontrollers AND also switch BETWEEN the other viewcontrollers.
All iOS patterns I know of seem to be problematic for that usecase:
UITabbarController would be the right choice if I could make the
tabbar disappear - it doesn't fit to the design. I was able to hide
the bar, but the viewcontroller screens don't resize themselves and
the whole thing feels hackish.
UINavigationController is designed for a sequential order of
screens, also the slide-in animation doesn't fit to the design
Modal viewcontrollers are also meant for a sequential order, additionally I have to keep
track of how many viewcontrollers are on the stack. Also, there is a
timing problem with dismissing a view controller and immediately
presenting the next one.
I could just switching views within a viewcontroller I guess, but the
viewcontrollers have all kinds of subtasks to do. I would end up with
one huge viewcontroller and lots of methods embedded for the
different views.
My question:
What would be the best approach to manage a bunch of viewcontrollers in any order I would like to?
Thanks for any help!
I would have a main UIViewController. That one would have references to the other three UIViewControllers. You can then do something like this from inside your main UIViewController:
[self.view addSubview:view1.view];
This works, but I wouldn't advise you doing because it's not the natural way of doing it. As stated by apple:
You should not use view controllers to manage views that fill only a
part of their window—that is, only part of the area defined by the
application content rectangle. If you want to have an interface
composed of several smaller views, embed them all in a single root
view and manage that view with your view controller.
Ok, my solution is not perfect, but seems to work:
Create a UINavigationController.
Use the viewcontrollers: method to add a stack of viewcontrollers to your liking.
When switching between viewcontrollers, rebuild the stack and attach again.
Problem: You only have the navigation controllers animation (slide in/out) at your disposal.
But you can disable the navigationcontrollers animation, get the next viewcontrollers view, animate that in with a UIView animation, then switch to the view controller itself through stack building as explained above.
Really far from perfect, but works.
I've noticed that if I create a UIViewController-derived class programatically (without using a nib) to be displayed with a call to presentModalViewController, as the view slides in, it's actually transparent by default until the view covers the entire screen, after which point the 'opaqueness' seems to kick in and the view beneath the modalview is no longer visible.
If I create the view using a nib, it slides in as you'd expect, fully covering any views beneath with no transparency issues.
I noticed that the Apple examples tend to use a nib-based view for ModalViews, but wondered why. Perhaps I'm missing something.....
It was down to a foolish coding error on my part.
I realised I'd copied/pasted some code from elsewhere into my ViewDidLoad
self.view.backgroundColor = [UIColor colorWithRed:0.6 green:0.4 blue:0.2 alpha:0.3];
I'd set a value of 0.3 for alpha.
Set it to 1.0 and transparency issue goes away...
Problem solved