I'm currently learning iOS Programming and I have a (hopefully) simple problem:
I wrote a drawing program that works with a customized class of UIView. That gets initialised upon startup in the main view controller in the viewDidLoad method
Image_DrawDraw *drawing = [[Image_DrawDraw alloc] initWithFrame:self.view.bounds];
[self.view addSubview:drawing];
I now want to change my program into a bit more sophisticated. I made a xib File containing some buttons, status bar and and image view. I still want to be able to draw in this new view, precisely over the image view, but not over the status bar or the buttons. But I have problems in initializing my Image_DrawDraw class it just overrides the whole xib and I'm back to my black screen where I can draw.
Thank you for your help!
When you add a subView to a view hierarchy it becomes the last item in the superview's views array property. The layering order of views is based on the views array, with the lowermost view the item at [views objectAtIndex:0] and the uppermost view the item at [views lastObject]. By arranging all of your other views on the Xib, and then adding your Image_DrawDraw view in code after the Xib has loaded, you are making it the uppermost view, so obscuring your buttons.
Instead of adding it in code, you could place it directly in the Xib.
Add a custom view to your xib. Position it above your existing xib image view, and below the buttons. Set the custom class of the view to Image_DrawDraw.
Now you won't need either of these lines of code:
Image_DrawDraw *drawing = [[Image_DrawDraw alloc] initWithFrame:self.view.bounds];
[self.view addSubview:drawing];
To refer to you Image_DrawDraw xib view in code, you should make an IBOutlet property for it in your viewController's #interface, and connect the Xib view to the IBOutlet by CTRL-dragging a line out in the Xib file.
Related
in ios6 I had UITextfield placed on UIAlertview to take inputs from user.
but in ios7 it don't seem to be working.
Any idea how to achieve that in ios7?
Thanks,
Virat
For the same task I'm creating UIView subclasses that I add as subviews to the main window. This way they will appear on top of everything and I'm in control of the layout & functionality.
How can one change the height of the container view dynamically depending on the amount of images of its childView?
It's a view like any other view, so you change it in the same way. You'll need to arrange to get a reference to it. When you set things up in the storyboard like this, you get an extra level of hierarchy that you wouldn't get if you created the parent-child view-controller architecture by hand (in code): there is a container view and inside that is the child view controller's view, whereas if you do it in code, there is no container view - the child view controller's view is all there is.
I am currently a little bit troubled by the following problem. I have a user interface which basically shows a graphic (a canvas made of Lines, Circles, ... these are all WPF objects). Depending on the selection a user makes in the menu, some items get deleted and some get added. So the basic image looks the same, but a few modifications are made.
The user has the possibility to select - say - 10 different "pages" by clicking a Next/Previous Button.
I am using MVVM Light and my ViewModel contains all the items of the graphic (all Lines, ...).
Now I would like to print that graphic to multiple pages. The first page should contain the graphic with changes from page 1, the second page contains the graphic with changes from page 2 and so on. The actual number of pages is dynamic. I track this with a property CurrentPage and a property PagesTotal.
Whenever I push the "Next" button, this causes a command to be executed which will change the variable CurrentPage and also makes sure that the correct items are displayed.
Now I would like to print this but this is where I'm stuck. I dont' mind leaving the MVVM zone and doing some dirty work in code-behind but I would refuse to draw everything again like in the old GDI days.
Any ideas are really welcome.
Create a UserControl containing your display logic (you graphic, for instance). Grab you ViewModel list and project then in UserControls, setting each ViewModel as each UserControl's DataContext.
Force each one to render calling Measure with infinite value and then Arrange with the resulting DesiredHeight and Width. Then follow the procedures to print WPF visuals (link link link).
Essentially, this should be quite simple if and only if your views work independently; i.e. your ViewModel doesn't contain UiElements that are placed into your View.
Simple solution is to basically print your visual root. If need be encapsulate your Views in a user control first.
PrintDialog printDlg = new PrintDialog();
UserControl1 uc = new UserControl1();
printDlg.PrintVisual(uc, "User Control Printing.");
Reference
Alright, I have to admin that I now switched back to doing the printing through code only. I would have really liked doing it "WPF-style" but handling the multiple pages issue was just too much trouble.
Anyway, there is still one issue regarding the printout left but this will be another question.
I stucked in a problem for 2weeks.
I have a UILabel which shows soundPlayer Current duration in my view. I use UIPageViewController so the user navigate throughout the pages(my view) like a real book. but when portion of another view controller appears, the label doesn't show the current progress.(because this is new instance of view controller).
How can I make this UILabel be static? I mean all instance of the ViewController have access to one UIlabel so all of them are only updating one label.
I can't use singeleton design pattern, because UIPageViewController needs at least 2 instance of my view controller.
the soundPlayer shoudn't be allocated every time new insatnce of viewcontroller is creating. how should I solve this dilemma?
you can see an example of my problem in weather live app. see the below image:
download sample code:
http://upload.ugm.ac.id/300paging.zip
the only change should I did is to create an static AVAudioPlayer
static AVAudioPlayer *soundPlayer;
soundPalyer is Static so there is one for all of instance objects of this class.
and in ViewDidLoad method:
if (!soundPlayer) {
soundPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundURL error:&error];
}
so when you navigating from one viewController to another viewController, soundPlayer wont initialized again and continue its playing.
thats all.
I have a view with a lot of labels and buttons which are created on code because in IB is too complicated. This works ok.
In IB I also created an input view which I want to appear from the bottom by the tap on a button. Very much like a keyboard if you will. Because this input view is strigth forward, it has been created on IB and it contains sliders, labels, etc. I haven't added it as a subview of self.view on IB.
By the tap of the button, I set up all the constrains for the input view: I set the width, I set it on the bottom of the self.view with vertical size, then I remove this constraint, I add the actual heigth and then I animate with [self.view layoutIfNeeded].
The thing is that the input view itsef animates correctly, but its subviews not so much. They kind of appear at once.
I have tried adding a input view programmatically, with only one switch. It animates quite nicely.
I'm guessing that there is a problem with the constrains between the controls and their superView. But I'm not sure about it, because although they do not animate correctly, they are on the correct place and witht the correct proportions. I guess I'm missing something here. Maybe it's not a good idea to mix IB set controls and views and programmatically modifying them?
Does somebody have any experience with that?
Thanks in advance,
I suggest you post to Apple's dev boards on this subject. I've seen several posts there recently. The Apple Engineers who replied said that with Autolayout, you basically give autolayout ownership of your view's center, size, and sometimes, transform.
To animate views that use autolayout, you should apparently use UIView block animation and animate the constraint settings on the views. The system will then animate the changes you make.
Not sure about adding new views programmatically and having them animate into place however.