How can i forward objects to separate subviews? - iphone

I have a UIView and a ScrollView as 2 separate subviews. How can i drag a UIView(named "a") from my UIView and have the scrollView "take over" that dragged "a" UIView?

It really depends on what you exactly mean by 'take over' the UIView.
If you simply want to change the parent view, when your view is 'dropped' then remove it as a Subview of it's parent view & add the UIView as a Subview of the UIScrollview.
If the original ParentView has a property that holds the UIView, then it will still retain the instance but the view will be one level down the hierarchy.
If you want to past the entire instance of the view to UIScrollView, you'll have to subclass UIScrollView & add a property for the UIView. Then you can either create a custom setter (i.e. don't #synthesize) that will retain the instance & do the above view adding/removing
OR
Create a - (void)provideNewView:(UIView *)newView method that will assign to the local property and do the view adding/removing.

Related

Notification when custom NSView has been added to a NSScrollView

Following on this question (Custom NSView embedded in NSSscrollView), when my custom view is embedded in a NSScrollView using IB, I can detect this in awakeFromNib method and perform the required initialization (I have to setup some scroll notifications).
My problem is when by custom view is added to a NSScrollView from code, setting the scrollview's documentView property. In this scenario is my custom view notified in any way (some NSView method that is called and I can override) or I have to perform my initialization explicitly after my view has been added to the scroll view?
The documentView of the scroll view is a subview of this scroll view and NSView has lots of usefull methods. In the chapter "Managing the View Hierarchy":
viewDidMoveToSuperview
Informs the view that its superview has changed (possibly to nil).
viewDidMoveToWindow
Informs the view that it has been added to a new view hierarchy.
When the view is added to a superview, viewDidMoveToSuperview is called. But the view could already be inside a view (in a XIB or in code) and this superview could be added to a scroll view. viewDidMoveToWindow is called when the view has been added to or removed from a view hierarchy.

How do you add pointsInside:withEvent to xib view?

I'm just learning iOS programming, so sorry if this is a dumb question.
I have a view in a xib that's acting as an overlay, but I want that view to be "transparent", so that people can manipulate (tap) the views below it. I read that pointsInside:withEvent will do it (if set to return NO), but where do I put this method?
I have a viewController that owns my xib, but putting the method there doesn't do anything...
How do I add my method to a xib view? Do I have to make another view (programmatically) and add my overlay xib as a subview?
Thanks
You can set userInteractionEnabled to NO on the view instead. Overriding pointInside:withEvent: is really for modifying the "shape" of the view.
If you do want to override pointInside:withEvent: you will need to make a UIView subclass and do it there. However you can still add this view inside your xib. Select the view in the xib, and in the Identity Inspector pane set the class to your subclass.

Disable UIView respond to UIIntefaceOrientationDidChange

I have a uiimageview within a uiview and I would like it to not rotate when uiinterfaceorientationdidchange is called but I would like everything else to rotate. Right now everything is rotating, how can I set certain objects not to rotate?
A UIImage has a property imageOrientation. Or, make a custom view controller with only a UIImageView and in the shouldRotateToInterfaceOrientation: method of thatcontroller return NO. Then, in the interface builder for your main view controller, add a custom object and change its class to your custom UIImageView. Or you can add it as a subview programatically.
Check out the UIViewController Class Reference for more info.

Adding an UIView over a MKMapView

I am trying to put a button in the corner of my MKMapView to control whether the map stays locked on to the user's location. What I have in mind is to create a UIView with a button on and add it over my MKMapView (not as an annotation or something) I can't figure this out with Interface Builder.
How can I add this button programmatically?
Controlling whether it actually follows the user etc. is already sorted - just need the button for it.
It looks like you are directly setting the controller's view outlet to an MKMapView object rather than a UIView object containing the MKMapView object. You cannot drop the button in such case on top of the MKMapView object in the IB. There are two ways you can deal with this,
Declare an outlet for the button and drop the button in the IB. This needn't be on top of the MKMapView object. Set the outlet to, say, a button property. Then in viewDidLoad do [self.view addSubview:self.button]; after setting the button's frame. (or)
Drop a new UIView object in IB and put the MKMapView object inside it. Set the controller's view to this container UIView object. Later drop the button on top of the MKMapView object and set it to its appropriate location.

UIViewController takes up entire screen in Interface Builder

I have a NIB with a UIView that contains some UILabels, UIButtons etc. and a UIViewController that is loading a UITableView from a detached NIB.
I want the UITableView in the UIViewController to be positioned below my UIView, but whenever I add it in Interface Builder it takes up the whole screen, and my UIView becomes part of the UIViewController.
How can I make sure the UITableView in my UIViewController appears below the UIView?
I want the UIViewController to be
positioned below my UIView
What you mean is you want the UIViewController's view positioned below your existing UIView. View controllers do not show up on screen themselves.
Create a new UIView instance in your nib, position it where you want, and assign it to be the view for the view controller.