TTThumbView/TTPhotoView no autorotation - iphone

In my app I try to use the TTphotoView, so in a ViewController I push the TTphotoView with my navigationController like this:
if(self.photoViewController == nil {
PhotoViewController *viewController = [[PhotoViewController alloc] init];
self.photoViewController = viewController;
viewController.hidesBottomBarWhenPushed = YES;
[viewController release];
}
[self.navigationController pushViewController:self.photoViewController animated:YES];
[self.navigationController  dismissModalViewControllerAnimated:YES]
the problem is when the user rotate the device on the PhotoViewController nothing happen.
EDIT : I can't believe people didn't have the same problem. If someone use the photoView in his application with his own navigation and not the TTNavigation can he tell me how did he push the ViewController?

I had the same problem.
I don't know why but TTScrollView deviceOrientationDidChange method in three20 code is commented out! If you uncomment it, it will work.
See the code here: http://github.com/facebook/three20/blob/master/src/TTScrollView.m

Have you overridden your application's:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
and returned YES for the landscape orientations?

My comment for willcodejavaforfood, as I told you I can force by doing something like for example that but too many problem inside, and the PhotoViewController of three20 must do it by himself so I don't want that:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(receivedRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
-(void) receivedRotate: (NSNotification *) notification {
NSLog(#"ORIENTATION CHANGE");
UIDeviceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation];
if(interfaceOrientation == UIDeviceOrientationLandscapeRight) {
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration: 0.5f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
self.view.transform = CGAffineTransformIdentity;
self.view.transform = CGAffineTransformMakeRotation(-M_PI/2);
self.view.bounds = CGRectMake(0.0, 0.0, 480.0, 320.0);
self.view.center = CGPointMake(240.0f, 160.0f);
[UIView commitAnimations];
}
}

Related

iPhone set interfaceorientation programmatically

I am trying to change the orientation of a single UIViewController programmatically. The user should choose in the settings if the view will be portrait or not. The value will be saved in NSUserDefaults and in the specific ViewController the orientation should be changed. So if Portrait is on the interfaceOrientation should be on UIInterfaceorientationUpsideDown......
I used following method but it will only change the orientation when the user will turn the device to landscape/portrait... otherwise nothing will be triggered.
- (BOOL)shouldAutoRotateToInterfactOrientation:(UIInterfaceOrientation)interfaceOrientation
Furthermore i tryied the next one (also with method name "setOrientation"):
[[UIDevice currentDevice] orientation: UIDeviceOrientationPortraitUpsideDown];
But again, nothing happens, there just appear errors because xcode sayes there are no methods with this name.
But ther should be another way to change it programatically...
the first method is also just a method that handles the actionListener after device position but there should be a way to call this actionListener in a direct way....
I just looked inside the UIApplication File but there is no usefull method....
You should use something like this code:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(rotationChanged:)
name:#"UIDeviceOrientationDidChangeNotification"
object:nil];
And then, change your view according to the orientation:
-(void)rotationChanged:(NSNotification *)notification{
NSInteger orientation = [[UIDevice currentDevice] orientation];
UIWindow *_window = [[[UIApplication sharedApplication] delegate] window];
switch (orientation) {
case 1:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.4];
[_window setTransform:CGAffineTransformMakeRotation (0)];
[_window setFrame:CGRectMake(0, 0, 320, 480)];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
[UIView commitAnimations];
break;
case 2:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.4];
[_window setTransform:CGAffineTransformMakeRotation (M_PI)];
[_window setFrame:CGRectMake(0, 0, 320, 480)];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
[UIView commitAnimations];
break;
case 3:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.4];
[_window setTransform:CGAffineTransformMakeRotation (M_PI / 2)];
[_window setFrame:CGRectMake(0, 0, 320, 480)];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:YES];
[UIView commitAnimations];
break;
case 4:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.4];
[_window setTransform:CGAffineTransformMakeRotation (- M_PI / 2)];
[_window setFrame:CGRectMake(0, 0, 320, 480)];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:YES];
[UIView commitAnimations];
break;
default:
break;
}
}
Hope it helps :P
Use this works perfectly on iOS7 and earlier.
[[UIDevice currentDevice] setValue:
[NSNumber numberWithInteger: UIInterfaceOrientationPortrait]
forKey:#"orientation"];
[[UIApplication sharedApplication] setStatusBarOrientation:yourDesiredOrientation];
You will then need to edit the shouldAutoRotate method (following example is for portrait:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
From previous answer:
[[UIDevice currentDevice] setValue:
[NSNumber numberWithInteger: UIInterfaceOrientationPortrait]
forKey:#"orientation"];
WARNING
I haven't a possibility to comment this answer so I'll edit it.
The author of this answer tries to set a value of UIInterfaceOrientation type to a variable of UIDeviceOrientation. They are both NSInteger enums, so compiler will not show a warning/error. But they have different meanings and "device" additionally has "face up" and "face down" orientations.

how to make the viewcontroller rotate when added through appdelegate window

I have added a viewcontroller in the window of appdelegate class like this:
-(void)showSearchView:(BOOL)view
{
if(view)
{
searchViewController = [[SearchView alloc] initWithNibName:#"SearchView" bundle:nil];
CGRect viewFrame=searchViewController.view.frame;
viewFrame.origin.y=-1024;
viewFrame.origin.x=248;
[window addSubview:searchViewController.view];
searchViewController.view.frame = viewFrame;
[UIView beginAnimations:#"UIBase Hidden" context:nil];
[UIView setAnimationDuration:0.5];
searchViewController.view.transform = CGAffineTransformMakeTranslation(0,1024);
[UIView commitAnimations];
}
else
{
[UIView beginAnimations:#"UIBase Shown" context:nil];
[UIView setAnimationDuration:0.5];
searchViewController.view.transform = CGAffineTransformIdentity;
[UIView commitAnimations];
[self performSelector:#selector(doTHis) withObject:nil afterDelay:1];
}
}
This gets called from other classes through this command
[apd showSearchView:YES];
where apd is object of appdelegate class
Everything is working fine till here but when i try to rotate it does not rotate. I have even returnd YES in the following method and still it does not rotate:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
What should be done?
Please remember that UIWindow does not rotate. Perhaps You should add a base view controller and do your rotation.

How to intercept iPhone rotation

in my app I got a Home with several buttons. Each button opens a separate view. In each view, if I put the device in landscape a help view is shown. Everything works fine except that in whatever view I am, if I put the iPhone like to lay on a table (I don't know how to eplain better...) the app exites from that view and comes back to the first view, the Home.
Here's my code:
- (void)viewDidLoad
{
[super viewDidLoad];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(orientationChanged:)name:#"UIDeviceOrientationDidChangeNotification"
object:nil];
[self performSelector:#selector (ritardo) withObject:nil afterDelay:5.0f];
}
-(void)orientationChanged:(NSNotification *)object{
UIDeviceOrientation deviceOrientation = [[object object] orientation];
if (deviceOrientation == UIInterfaceOrientationPortrait)
{
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
self.view = self.portraitView;
}
else if (deviceOrientation == UIInterfaceOrientationLandscapeLeft || deviceOrientation
== UIInterfaceOrientationLandscapeRight)
{
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
self.view = self.landscapeView;
}
[UIView commitAnimations];
[self dismissModalViewControllerAnimated:NO];
}
-(void) ritardo {
ruota.image = [UIImage imageNamed:#"RuotaPerAiuto.png"];
}
- (void)viewDidUnload
{
[self setPortraitView:nil];
[self setLandscapeView:nil];
[self setRuota:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
#end
Hi hope you can help me
EDIT:
I modified the -(void)orientationChanged:(NSNotification *)object{ in this way:
-(void)orientationChanged:(NSNotification *)object{
UIDeviceOrientation deviceOrientation = [[object object] orientation];
if (deviceOrientation == UIDeviceOrientationFaceUp)// || deviceOrientation ==
UIDeviceOrientationFaceDown)
{
return;
}
if (deviceOrientation == UIInterfaceOrientationPortrait || deviceOrientation ==
UIInterfaceOrientationPortraitUpsideDown)
{
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
self.view = self.portraitView;
}
else
if (deviceOrientation == UIInterfaceOrientationLandscapeLeft || deviceOrientation ==
UIInterfaceOrientationLandscapeRight)
{
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
self.view = self.landscapeView;
}
[UIView commitAnimations];
[self dismissModalViewControllerAnimated:NO];
}
Now, if I'm in portrait and get the iPhone to faceUp position works good. But when I change position from faceUp to portrait it goes back to the home...
The problem is that UIDeviceOrientationDidChangeNotification will be fired independently from shouldAutorotateToInterfaceOrientation. And you don't handle the cases UIInterfaceOrientationPortraitUpsideDown, UIDeviceOrientationFaceUp and UIDeviceOrientationFaceDown in the method orientationChanged:. So when the device is rotated to one of these orientations, your code is equivalent to:
-(void)orientationChanged:(NSNotification *)object
{
[UIView commitAnimations];
[self dismissModalViewControllerAnimated:NO];
}
So you should remove the lines:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(orientationChanged:)name:#"UIDeviceOrientationDidChangeNotification" object:nil];
and put you code in the method willRotateToInterfaceOrientation:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) {
self.view = self.portraitView;
} else {
self.view = self.landscapeView;
}
[UIView commitAnimations];
[self dismissModalViewControllerAnimated:NO];
}
Edit
If you want to keep orientationChanged, then modify it as follows:
-(void)orientationChanged:(NSNotification *)object{
UIDeviceOrientation deviceOrientation = [[object object] orientation];
if (deviceOrientation == UIInterfaceOrientationPortrait) {
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
self.view = self.portraitView;
[UIView commitAnimations];
[self dismissModalViewControllerAnimated:NO];
} else if (deviceOrientation == UIInterfaceOrientationLandscapeLeft || deviceOrientation == UIInterfaceOrientationLandscapeRight) {
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
self.view = self.landscapeView;
[UIView commitAnimations];
[self dismissModalViewControllerAnimated:NO];
}
}

scroll view is not responding when navigated again

i had created a navigation based small application. When I click to the table row, it display controller having UIScrollView and number of TextFields added in it, when i returned back to main controller, then again i navigate to that controller, it do not scroll and still contain previous values in textfield. I am not able to know where is the problem.
Here is my code:
rootcontroller.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
switch(indexPath.row)
{
case 1:
if(insertViewController == nil)
insertViewController = [[insertView alloc] initWithNibName:#"insertView" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:insertViewController animated:YES];
break;
//[insertViewController release];
}
}
insertviewcontoller.m
#import "insertView.h"
#import "RootViewController.h"
#import "Foundation/Foundation.h"
#define kTabBarHeight 5.0
#define kKeyboardAnimationDuration 1.0
#implementation insertView
#synthesize scroll;
- (void)viewDidLoad {
[super viewDidLoad];
//for scrolling
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:self.view.window];
// register for keyboard notifications
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:self.view.window];
keyboardIsShown = NO;
//make contentSize bigger than your scrollSize (you will need to figure out for your own use case)
CGSize scrollContentSize = CGSizeMake(320, 345);
self.scroll.contentSize = scrollContentSize;
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardWillShowNotification
object:nil];
// unregister for keyboard notifications while not visible.
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardWillHideNotification
object:nil];
}
- (void)keyboardWillHide:(NSNotification *)n
{
NSDictionary* userInfo = [n userInfo];
// get the size of the keyboard
NSValue* boundsValue = [userInfo objectForKey:UIKeyboardBoundsUserInfoKey];
CGSize keyboardSize = [boundsValue CGRectValue].size;
// resize the scrollview
CGRect viewFrame = self.scroll.frame;
// I'm also subtracting a constant kTabBarHeight because my UIScrollView was offset by the UITabBar so really only the portion of the keyboard that is leftover pass the UITabBar is obscuring my UIScrollView.
viewFrame.size.height += (keyboardSize.height - kTabBarHeight);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
// The kKeyboardAnimationDuration I am using is 0.3
[UIView setAnimationDuration:kKeyboardAnimationDuration];
[self.scroll setFrame:viewFrame];
[UIView commitAnimations];
keyboardIsShown = NO;
}
- (void)keyboardWillShow:(NSNotification *)n
{
// This is an ivar I'm using to ensure that we do not do the frame size adjustment on the UIScrollView if the keyboard is already shown. This can happen if the user, after fixing editing a UITextField, scrolls the resized UIScrollView to another UITextField and attempts to edit the next UITextField. If we were to resize the UIScrollView again, it would be disastrous. NOTE: The keyboard notification will fire even when the keyboard is already shown.
if (keyboardIsShown) {
return;
}
NSDictionary* userInfo = [n userInfo];
// get the size of the keyboard
NSValue* boundsValue = [userInfo objectForKey:UIKeyboardBoundsUserInfoKey];
CGSize keyboardSize = [boundsValue CGRectValue].size;
// resize the noteView
CGRect viewFrame = self.scroll.frame;
// I'm also subtracting a constant kTabBarHeight because my UIScrollView was offset by the UITabBar so really only the portion of the keyboard that is leftover pass the UITabBar is obscuring my UIScrollView.
viewFrame.size.height -= (keyboardSize.height - kTabBarHeight);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
// The kKeyboardAnimationDuration I am using is 0.3
[UIView setAnimationDuration:kKeyboardAnimationDuration];
[self.scroll setFrame:viewFrame];
[UIView commitAnimations];
keyboardIsShown = YES;
}
- (void)dealloc {
[super dealloc];
[scroll release];
[nmtf release];
[phtf release];
[addtf release];
}
update viewDidLoad method into viewWillAppear:(BOOL)animated in your insertviewcontoller.m page

iPhone Swipe Gesture crash

I have an app that I'd like the swipe gesture to flip to a second view. The app is all set up with buttons that work. The swipe gesture though causes a crash ( “EXC_BAD_ACCESS”.).
The gesture code is:
- (void)handleSwipe:(UISwipeGestureRecognizer *)recognizer {
NSLog(#"%s", __FUNCTION__);
switch (recognizer.direction)
{
case (UISwipeGestureRecognizerDirectionRight):
[self performSelector:#selector(flipper:)];
break;
case (UISwipeGestureRecognizerDirectionLeft):
[self performSelector:#selector(flipper:)];
break;
default:
break;
}
}
and "flipper" looks like this:
- (IBAction)flipper:(id)sender {
FlashCardsAppDelegate *mainDelegate = (FlashCardsAppDelegate *)[[UIApplication sharedApplication] delegate];
[mainDelegate flipToFront];
}
flipToBack (and flipToFront) look like this..
- (void)flipToBack {
NSLog(#"%s", __FUNCTION__);
BackViewController *theBackView = [[BackViewController alloc] initWithNibName:#"BackView" bundle:nil];
[self setBackViewController:theBackView];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:window cache:YES];
[frontViewController.view removeFromSuperview];
[self.window addSubview:[backViewController view]];
[UIView commitAnimations];
[frontViewController release];
frontViewController = nil;
[theBackView release];
// NSLog (#" FINISHED ");
}
Maybe I'm going about this the wrong way... All ideas are welcome...
Why are you even using performSelector: Just because a method is marked as an (IBAction) doesn't make it any different from any other method, and you can send them as messages to a class instance
- (void)handleSwipe:(UISwipeGestureRecognizer *)recognizer {
NSLog(#"%s", __FUNCTION__);
if ((recognizer.direction == UISwipeGestureRecognizerDirectionRight) || (recognizer.direction == UISwipeGestureRecognizerDirectionLeft)) {
[self flipper:nil]
}
}
Actually, since the gesture directions are just bit flags this can be written as:
- (void)handleSwipe:(UISwipeGestureRecognizer *)recognizer {
NSLog(#"%s", __FUNCTION__);
if (recognizer.direction & (UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft)) {
[self flipper:nil]
}
}
Your selector needs to take an argument as implied by the : character in the name, so you should use performSelector:withObject:.
[self performSelector:#selector(flipper:) withObject:nil];