Allow to view image in landscape in portrait-only app - image

I am making an iPhone and iPod app that I will make in portrait mode only. There comes a point in the app where if the user touches a picture, it will make itself fullscreen. The way I do that is via a segue to another view controller, where a UIImageView takes the whole space. I would like to be able to rotate the device in landscape to view the picture in landscape.
How it that possible?
In a second phase: I would like to know how to make the view fullscreen, so the picture could fill the entire screen.
Basically: I want the picture to behave just like the twitter app. :)
Thanks
EDIT: here is the code in my Class to view the image
#import "ImageViewer.h"
#interface ImageViewer ()
#end
#implementation ImageViewer
#synthesize scrollView;
#synthesize imageView;
#synthesize image;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
CGRect imageFrame = CGRectMake(0, 0, self.imageView.image.size.width, self.imageView.image.size.height);
self.imageView.frame = imageFrame;
self.scrollView.contentSize = imageFrame.size;
}
- (UIView *) viewForZoomingInScrollView:(UIScrollView *)sender
{
return self.imageView;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
NSLog(#"rotate.");
return YES;
}
- (void)viewDidUnload {
[self setImageView:nil];
[self setScrollView:nil];
[super viewDidUnload];
}
#end

Related

iPhone SDK: Buttons and Labels causing UIScrollView to not scroll

I have been dealing with this all day and I simply cant find what the heck is going wrong. I have a scrollview inside a viewcontroller, but when i add a label or button to the view the scroll view stops scrolling. This is so standard i've done it hundred of times but for some reason its acting up now. Hope someone can help.
.h
#interface Test : UIViewController{
IBOutlet UIScrollView *scrollView;
}
-(IBAction)goBack;
#end
.m
#interface Test ()
#end
#implementation Test
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
scrollView.contentSize=CGSizeMake(320.0,1100.0);
}
-(IBAction)goBack
{
[self dismissModalViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end

How to change value in UISegmentedControl?

I have set up a segmented control in my project. I want to use it in my settings scene to control whether the orientation is landscape left or landscape right. I have in set up in my storyboard and here is my code in my SettingsViewController.h
#import <UIKit/UIKit.h>
#interface SettingsViewController : UIViewController
{
IBOutlet UISegmentedControl *orientation;
}
#property (nonatomic, retain) UISegmentedControl *orientation;
- (IBAction) setOrientation;
#end
and here is my code in SettingsViewController.m
#import "SettingsViewController.h"
#implementation SettingsViewController
#synthesize orientation;
- (IBAction)setOrientation
{
NSLog(#"index = %d\n", orientation.selectedSegmentIndex);
if (orientation.selectedSegmentIndex == 0) {
NSLog(#"left\n");
}
if (orientation.selectedSegmentIndex == 1) {
NSLog(#"right\n");
}
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
#end
I was wondering why the value isn't changing from 0 to 1 when I select the right side of the control. Also I was wondering if in my .h I need to declare IBOutlet because I dont use the segmented control as an outlet. I just use it to take in which side is selected and then use that to set the orientation of the app.
Try this. Hook it up in the Storyboard to the segmentedControl using valueChanged.
- (IBAction)segmentedControlChanged:(id)sender {
UISegmentedControl *segmentedC = (UISegmentedControl *)sender;
if (segmentedC.selectedSegmentIndex == 0) {
// NSLog(#"selectedSegmentIndex == 0");
[self selectFirstSegment];
}
}
in segment action set the orientation landscape or potriat..and in .m file end of bool orientation type method set
return yes;
in all .m files .

A Button to make a TextView from invisible to visible

iam a newbie in Xcode programming and i didnt find the right answer in another Tread.
My Question: I have a Detailview with a CardQuestion(TextView) and a CardAnser(TextView).
How is the method to change the invisible Answer to visible.
On Action the Button "Show Answer".
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = self.chosenCard.name;
self.cardName.text = self.chosenCard.name;
self.cardQuestion.text = self.chosenCard.question;
self.cardAnswer.text = self.chosenCard.answer;
}
- (void)viewDidUnload
{
[self setCardName:nil];
[self setCardQuestion:nil];
[self setCardAnswer: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
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (IBAction)toAnswerButton:(id)sender{
}
#end
I hope you can understand my question.
UIView subviews (including UILabel, UITextField and UITextView) have a hidden property. Set that to YES to hide a view and to NO to unhide it. You can also set this property in Interface Builder.

Cocoa -- getting a simple NSImageView to work

I am confused about why this code does not display any image:
In the app delegate:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSRect rect = window.frame;
rect.origin.x = 0;
rect.origin.y = 0;
BlueImageView *blueImageView = [[BlueImageView alloc]initWithFrame:rect];
window.contentView = blueImageView; // also tried [window.contentView addSubview: blueImageView];
}
BlueImageView.h:
#interface BlueImageView : NSImageView {
}
#end
BlueImageView.m:
#implementation BlueImageView
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self setImage: [NSImage imageNamed:#"imagefile.png"]];
NSAssert(self.image, #"");
NSLog (#"Initialized");
}
return self;
}
- (void)drawRect:(NSRect)dirtyRect {
}
#end
The file imagefile.png exists. The NSAssert is not causing an exception. The NSLog is firing. But no image shows up in the window.
The drawRect: method is called to draw the view, and your implementation immediately returns. To get NSImageView to draw the image for you, call [super drawRect:dirtyRect]; in your implementation of drawRect:. If you aren't going to do any other drawing in drawRect:, just remove the method to speed up drawing.

Is this a bug for EKEventEditViewController

I found EKEventEditViewController is not correct in
UIInterfaceOrientationPortraitUpside.
Try this demo from your site, I just changed code as below, put simulator to
UpSide Down Portrait mode, then click "+" button, you will find the screen in
flash, this is due to dialog is upside in short time.
Then you can try it on device turn to UpSideDown mode, you will see what I am talking:)
I want to know why they have different view in Simulator or iPad even if it is
not a bug.
Bug in SimpleEKDemo
Basically you would want to Create your own class that inherits from EKEventEditViewController and use that everywhere you would use normally use EKEventEditViewController. For example, KonopEventEditViewController.
KonopEventEditViewController.h is as follows
#import <EventKitUI/EventKitUI.h>
#interface KonopEventEditViewController : EKEventEditViewController
#end
KonopEventEditViewController.m is as follows
#import "KonopEventEditViewController.h"
#interface KonopEventEditViewController ()
#end
#implementation KonopEventEditViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
#end

Resources