Rotate only subview of a uiviewcontroller - ios7

I read up other questions and it isn't very clear, as to what I could do about this problem.
Decided to ask anyway.
So I have a UIViewController, wherein I block auto-rotation.
I bring up one of the subviews added to the controller. Now, I rotate the device. And this UIView should change orientation, I will use autolayout to support all orientations on this view alone.
Is this possible?
What I tried is to, listen for device orientation changes, and then send the orientation to the subview and then was thinking probably transform, but that won't be accurate and it is probably a lot of work.
Any clue?

So, there isn't any direct method without using another view controller to hitch the view to. Add a new UIViewController and make your UIView the view controller's view. Add your rotation parameters/methods to the newly made view controller.
So its not the best solution because I have to now present that view from a view controller which is adding more code. That's kinda fundamental to a UIView. It can't handle itself unless you write hacks and override your view's behavior.
Another solution is to listen to changes in interface orientations and then relayout your view based on that change.

Related

UIWebView redraw on rotate

I have implemented a UIWebView object into a custom UIView (TSAlertView). My UIWebView sits in the middle of the UIView, as a subview.
When I rotate the iOS device screen, the UIWebView object redraws right on top of the old one, without deleting the old one. All the other elements of this custom UIView are destroyed and redrawn when the screen is rotated.
I imagine I must have missed some sort of procedure for deallocating resources or removing the UIWebView from view. I have tried adding 'autorelease' to the declaration of the UIWebView, but to no avail. I wonder if this is a common symptom of a simple oversight I have made in the way the UIWebView is created?
This seems to be a simple case of not telling the UIWebView object it should destroy itself before it is redrawn on each rotate - but I don't know how I can go about this...
Any wisdom gratefully received.
Ideally while rotating you should not create the views again. Instead you can rearrange the frame in delegates appropriately. In your case you might be creating a UIWebView again, which should be avoided. Instead of that, you can keep it as a class level param(Declare in .h file) and adjust the frame in delegate methods for rotation. Also please note that release/autorelease wont remove your view from superview. You need to call removeFromSuperview method to achieve that.
Check this for view resizing and layout handling

Custom segue - Individually animate UINavigationBar and UITableView

Is there a way to use custom segues to individually animate several different subviews.
For example, I want my modal view to appear by the UINavigationBar fading in (as the source destination's UINavigationBar fades out) and then a UITableView to slide down the screen 'over' the source destination's view controller.
When I try to implement this in the - (void)perform method. My properties don't animate using [UIView animateWithDuration: animations: completion:].
Can anyone provide me with a solution?
Thanks in advance!
You can certainly use custom segues to achieve this - however, I don't think you'll get much help without more details about the setup of your view controllers.
Everything you describe is correct: to create a custom segue you animate the views inside your sourceViewController and destinationViewController inside the segue's perform: method. If they're not animating you might want to check that your segue is actually getting called (you can use breakpoints in the debugger to check this), or that the views you're trying to access inside your view controllers actually exist at that point in time (again, something you can check using the debugger).
For a solution specific to your app you're almost certainly going to have to provide more details about the two view controllers you're trying to transition between. Perhaps you could post your perform: method.

Custom UISplitViewController?

I want the effect of a UISplitViewController however I am not using the split view template.
Is it relatively easy to achieve without the template? And with using normal UIViewController?
What I want it a customary sized and positioned UITableView which then has a customary sized detail view which then of course goes into a popover and detail view when portrait.
Doing it without Interface Builder, you would create a UIViewController class. In the viewDidLoad method of that class, create a UIView or a UITableView with the frame origin where you want it and a size that you want. (Release it in the viewDidUnload method.) Then set the UIViewController's self.view to point to this new view.
self.view = [[UIView alloc] initWithFrame:...]; // edit - added in response to your question
If you created a UIView, then you will want to put your UITableView inside this new view. (This approach lets you add more items to the container UIView if you need to.)
Make sure your UIViewController adheres to the UITableViewDelegate and UITableViewDataSource protocols. Add the delegate and datasource methods and you should be good to go.
This new view can cover other views, or you can size the other views to fit beside it. You only need to set there frames according to what you want to do with them.
There are some limitations if you use a UITableViewController, so a lot of people recommend using a UIViewController instead. like I described above. You can google for more info on that topic.
Just great a new temporary Xcode-project from that template and judge yourself, if it is complicated for you, to adept your (real) code.
Yes. You can do it quite easily. Just use delegates to pass messages between the left and the right side views (root and detail). For instance the didSelectRowAtIndexPath tableView method could be used along with delegation to pass a message to the right sided detail view. Tap a cell on the left table, show its text as a Label on the right side. Its just a simple example. And yes you can handle the rotations and send left side view into a UIPopoverController as well, thus giving the detail view full screen real estate in Portrait orientation.
Also try MGSplitViewController . It gives you a lot of other customization options on a split view controller.

How to get UINavigationController to rotate, but not the subview?

I downloaded the free iPad application "SketchBook Express" by "Autodesk".
In it, they have a drawing surface, and (what I believe is) a UINavigationController. What interests me is that the navigation controller bar rotates with the iPad, but the content of the drawing does not. So if I put the iPad from portrait to landscape, the nav bar moves to the new top, but the sketch I've drawn is now on its side. I would like to implement something similar for my program, but I have been unable to.
I've played with shouldAutorotateToInterfaceOrientation: but so far I've just figured out it is only called once. I made a subclass of UINavigationController and had that return YES, and had my subview controller return NO. That did not do the trick.
Is there a simple way to do this?
What rotates is probably contained by a UIViewController (or UINavigationController)'s view.
Other things (that don't rotate) are probably contained by a view that is not contained by any UIViewController (or a controller that returns NO in shouldAutorotateToInterfaceOrientation method).
This means that you could try setting your drawing view as a subview of the keyWindow.
Other things could be in the view controller as usual.
Is not I have tried, this is just an idea. And I would be interested in knowing if this worked. :)

touchesBegan method is not being called

I am trying to detect touches, but the touchesBegan method is not being called.
In my ViewController, I have added the touchesBegan method. My Nib files owner is set to the correct V.C. The Nib itself consists of the view, with a scroll view and a tab bar. Nested in the scroll view is an image view, which has user interaction enabled. What is precluding touches from being registered, or preventing my implementation of touchesBegan from being called?
I've scoured the Internet and Apple docs, and I can't see what I am doing wrong. Also, I'm not really sure what code I can post here to help with my query. Thanks.
Okay, after a lot more reading, I've now got a scrollview and a imageview, both of which are created programatically. The imageview is a sub view of the scrollview, and scrollview has been subclassed so that the touches ended method can decide whether it was a single touch, in which case call the touches ended method from the view controller, otherwise call its supers method. This works just fine, however, why is it that this cannot be done without subclassing scrollview? Is it my lack of understanding of how scrollview works, or is it just a limitation of it?