iPhone SDK: Buttons and Labels causing UIScrollView to not scroll - uiscrollview

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

Related

xcode 6 Beta - strange warning for ViewPort delegates

One of the example projects in XCode 5 was named "Utility Application". It had a main view and an alternate view and set up an Info button to flip the main view to the alternate view. It used a viewcontroller delegate and a protocol definition to switch back from the flip view to the main view. In XCode 6 it is no longer there.
When I run this simple XCode 5 example app in XCode 6, I get a warning in the method below:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"showAlternate"]) {
[[segue destinationViewController] setDelegate:self]; //<<<< Here is where the warning appears
}
}
The warning is: Sending 'MainViewController *const_strong' to parameter of incompatible type 'id'
What is this? A bug? The app runs fine on both simulator and iOS device. Below is the entire code. Any help will be much appreciated.
**// MainViewController.h
#import "FlipsideViewController.h"
#interface MainViewController : UIViewController <FlipsideViewControllerDelegate>
#end
// MainViewController.m
#import "MainViewController.h"
#interface MainViewController ()
#end
#implementation MainViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Flipside View
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller
{
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"showAlternate"]) {
[[segue destinationViewController] setDelegate:self]; //<<<< Here is where the warning appears
}
}
#end
// FlipsideViewController.h
#import <UIKit/UIKit.h>
#class FlipsideViewController;
#protocol FlipsideViewControllerDelegate
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller;
#end
#interface FlipsideViewController : UIViewController
#property (weak, nonatomic) id <FlipsideViewControllerDelegate> delegate;
- (IBAction)done:(id)sender;
#end
// FlipsideViewController.m
#import "FlipsideViewController.h"
#interface FlipsideViewController ()
#end
#implementation FlipsideViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Actions
- (IBAction)done:(id)sender
{
[self.delegate flipsideViewControllerDidFinish:self];
}
#end**
You may have figured this out already...just wanted to post a link for for those stumbling upon this: getting a warning setting up delegate for a custom protocol

Allow to view image in landscape in portrait-only app

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

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 .

Adding three subviews each with Navigationcontroller Stupid?

Hello i created three books(UIViews) each with it's own Navigationcontroller for paging.
My questions
!) Does it make any sense to use three Navigationcontroller
2) Is my code below any good? It seems to work but the bar has a ofset of 20px from the top.
#import "Book_01.h"
#implementation Book_01 // UIViewController
#synthesize book_01_NavigationController;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
[self.view addSubview:book_01_NavigationController.view];
}
return self;
}
Man, your code it's okei. But, you need to declare your navigation controller first:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
book_01_NavigationController = [[UINavigationController alloc] initWithRootViewController:self];
[self.view addSubview:book_01_NavigationController.view];
}
return self;
}
About ofset of 20px from the top. That's because your status bar it's hidden. You need to adjust the elements to fullscreen.
[]'S

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