TTPhotoViewController thumbnails rotate but images don't - iphone

I have PhotoTest1Controller very similiar to the one in Three20 samples. I implemented necessary shouldRotate methods in necessary places in UITabBarController and UINavController derived classes as well as the table that contains PhotoTest1Controller.
A funny thing is happening, when in thumbnail mode, the view rotates properly, but when showing a picture it does not respond to rotation. Moreover, If I rotate in thumbnail view and then switch to single image view in that rotation, I find that the image is properly rotated in the background. It only ignores rotation when it is the topmost view!
So, my understanding is that shouldRotate events are properly propagated, but for some reason single image view does not rotate when in top view, unlike the example code which is %98 equal to my code...

I found the answer to my own problem and answered it here: TTThumbView/TTPhotoView no autorotation
Briefly: I don't know why but TTScrollView deviceOrientationDidChange method in three20 codebase is commented out! If you uncomment it, it will work.
See the code here: http://github.com/facebook/three20/blob/master/src/TTScrollView.m

Related

Unable to get the correct frame for UIViewControllerAnimatedTransitioning to UIPageViewController

I have been battling this transition animation and I am pretty much out of ideas. I am attempting something similar to going from the collection to the individual photos in the Photos app on iOS.
It all works to my satisfaction with the exception that the frame for the "big" detail view of the image is not correct. It is the right size but it is about 87 points closer to the top of the screen compared to the actual position of the image in the final state. This is pretty much the same height as what is above the "safe area" (iPhone X titles + navItem) and irritatingly close to what is also below the safe area (toolbar and iPhone X home area).
I have Googled (and "SO'd") a bunch of different solutions to similar sounding problems. E.g: UIViewControllerAnimatedTransitioning with Safe Area Insets on iPhone X
I have downloaded and perused example code from Github. E.g: https://github.com/SamStone92/CustomTransitions
It seems to me that I have something in my view (controller) hierarchy which is complicating this more than most. I would love some hints as to what might be causing the problem and how I might go about fixing it.
My hierarchy is:
NavigationController containing the root VC with a UICollectionView.
Tapping a cell transitions to a UIPageViewController for a "detail view" where I can page between items in the collection.
UIPageViewController has a bottom toolbar in addition to the navigation bar.
The content ViewController has a ScrollView with a UIImageView in it to get some zooming.
Seems like the common approach is to add the destination view to the container, force a layout pass and then get the frame. I have tried many variants of this with and without converting the coordinates. (they appear to always remain the same before and after conversion)
My Theory
I am leaning towards the UIPageViewController being the complicating factor. But I have not been able to untangle how to get the correct coordinates.
The destination view (in the animation) is not the content view but the PageVC view which in turn may or may not have added the content view, adapted it to the navigation item or the toolbar.
Seems like viewWillAppear on the content VC does not have the right coordinates. I can tell that the detail content view is getting a call to viewWillLayoutSubviews after that and also after all the animation delegation stuff has had its turn.
This is a color overlay of my main views. Grey is the top and bottom areas outside the safe area. Blue is where the transition animates to before revealing the green, underlying actual position it should have animated to.

iphone 5 and storyboard setting autoresizing masks

I've got a storyboard-driven application, and I'm trying to modify it to support the iPhone 5.
There is a navigation controller, and then my menuViewController. In viewDidLoad of the menu controller, I have verified that self.view.frame is {{0, 0}, {320, 568}}. The view controller's size is set to "Inferred" in the Simulated Metrics, and the main view has "Autoresize Subviews" checked.
But my subviews are not getting resized! (Note that I can manually resize them in code, that's not a problem, but I would really like this to "work" using mostly IB, since I have a lot of views, and that would be about a million times easier.)
I have a full-screen subview that doesn't get resized. It's mask has basically everything enabled.
I also have subviews that are supposed to float at either the bottom or the top, and the ones that float at the top work, but the ones that are supposed to float at the bottom don't.
What should I be checking here? It's probably something stupid that i'm missing, but I've been scratching my head for an hour, and am getting close to just changing all my frames in code. (Which would be ugly as well as inelegant.)
Thanks!
I found a hint here: How to resize App for Iphone 5?
Essentially one of the answers there suggests editing the xml of the storyboard directly. I went in and looked, and the top level view in my viewController had autoresizesSubviews="NO" I changed it to YES, and that fixed the problem for me.
As stated in my original post, I absolutely know for sure that checkbox was checked in the inspector pane. I have no idea why the xml didn't match the inspector.
Check the springs in the autoresize control for your view (not the view controller) within the metrics pane. Try and make them like in the picture below.
Notice that you will not be able to set the internal springs for a top-level view object (but that's fine: just ensure the 4 side ticks are all activated).
Hope this helps.

How to draw in UIViewController in landscape orientation on the iPhone?

there are already some questions on this topic. Unfortunately none of them helped me in anyway. So here is the thing. I am working on an app atm and it has one tabcontroller with two tabs, which contain multiple navigationcontroller on top of each other. Now in one tab at the top level navigation controller, I want to draw some graphics in landscape orientation.
Unfortunately using the shouldAutorotateToInterfaceOrientation method returning YES does not help in anyway.
Now I was wondering whether I could just hide the statusBar and the navigationBar and then draw my graphics so that it looks like it is landscape orientation. But then I also would like to add some labels. I am quite sure I also could turn those around 90 degrees. But this is probably not the right approach here. And I want to submit my app someday...
So now I was hoping someone knows whats the best approach here and how to realize it.
Thanks.
I found a solution somewhere else. The idea is to use the CGAffineTransform method. It allows you to transform the complete coordinate system of a uiview. The piece of code underneath rotatets it to landscape. Now when you draw, the drawing relates to the rotated coordinate systems and everything is drawn in landscape orientation.
CGAffineTransform transform=CGAffineTransformIdentity;
transform=CGAffineTransformRotate(transform, (90.0f*22.0f)/(180.0f*7.0f));
transform=CGAffineTransformTranslate(transform, 80, 80);
This does what I want. But anyway, if there are any other suggestions, please post them!

How do I properly handle rotation of a UIScrollView containing UIImageViews?

I'm developing an image viewer, much like the Photos App.
It's a UIScrollView with paging enabled with images loaded from the internet, so I've adapted portions of the LazyTableImages sample. The Scroll View and each ImageView inside of it have all of their autoresize mask flags set.
When I first observed how resizes were happening during rotation, it looked good, but once I started trying to interact with the scroll view, I realized that I also had to programmatically change the size of the contentView. I did that by implementing didRotateFromInterfaceOrientation: in my view controller.
[self.scrollView setContentSize:CGSizeMake(numberOfImages * portraitWidth, [scrollView bounds].size.height)];
With interaction behaving properly, I then discovered that, if I was viewing the second photo and rotated, portions of both the 1st and 2nd photos would be shown on the screen. I needed to change the contentOffset as well.
I've tried to fix this two ways - both by using the scrollRectToVisible:animated: method of UIScrollView, as well as trying to set the contentOffset property directly. And I've experimented by putting this code in implementations of both the "one-step" and "two-step" responses to changes in Orientation. For example:
-(void)didAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
[self.scrollView setContentOffset:CGPointMake(currentlyViewedPhotoIndex * largeImageHeight,0) animated:YES];
In all cases though, it just looks janky as hell. Either I clearly see the scroll happen, or it just jumps. Uuuuuuuuuuugly! Is there a way to do this so that it behaves exactly like the Photos app does?
What I wound up doing instead - just before rotation starts, hide the UIScrollView and create a UIImageView that contains the currently viewed image. Rotate, that image will rotate all nice and pretty, and when rotation completes remove the ImageView and unhide the Scroll View.
Update - if you're reading this today (anytime after iOS 6), use a UIPageViewController and set transitionStyle to UIPageViewControllerTransitionStyleScroll, for crissakes.
I did something slightly different when faced with the same problem. In willRotateToInterfaceOrientation:duration:, I hide all of the UIScrollView's subviews except for the currently displayed subview, and in didRotateFromInterfaceOrientation: I unhide the subviews.

Maintaining proportions when autorotating custom UIView

This is probably either real easy, real dumb, or my google fu has taken a serious turn for the worse. Anyway, I'm implementing custom view for my app, which is using pure CGContext drawing, no subviews (for now at least). The thing is, I want it to autorotate, so I have shouldAutorotateToInterfaceOrientation return YES, and voila, the view rotates. But in doing so it's not actually redrawing the content (which I assume is rendered into a texture somewhere in the framework and splashed onto a rect, but that's not really relevant here), the rect is simply stretched, squishing the content. How can I get it to simply issue a draw of a bigger area while rotating? That is, my content is bigger than the screen, and I'd simply like the viewport to change during the rotation.
I've tried setting the view's contentMode to UIViewContentModeRedraw, but that didn't do anything, I've tried playing around with the autoresizeMask stuff, but didn't seem to help either. I've also tried inserting a setNeedsDisplay in willRotateToInterfaceOrientation, however that only caused it to redraw using the new bounds (i.e. squishing it first, and then stretching it out to the right size during the rotation), which is also not what I'd like to see.
Does anyone have any idea how I might go about getting this to work?
As it turns out, it's a mix of dumb and easy. I'm posting it here if anyone should care to read it someday. They way I managed to solve it was actually sandwiching a view between window and my view (I suppose you might be able to go to work on the window directly, but it felt more intuitive this way). That is, I added my view as a child view to that view, which I'll call the frame.
The frame is a resizing as normal, however, I turn OFF resizing of child views, and make my own view LARGER than the viewing area (square actually, 480x480, so it can cover the entire screen either way). Problem solved, basically.
Now I'm playing around with animating the offset of the view in the frame during willRotateToInterfaceOrientation, to have it appear to be rotating around the center, rather than the upper left corner, but that's a different question.