Embedded YouTube Video in Landscape - objective-c

I have an embedded YoutTube video in my app. The entire app is locked into only running in portrait but I'd like the video to play in landscape once the user taps the play button on the thumbnail. Here is the code for the embedded YouTube video.
//
// YouTubeView.h
// KFBNewsroom
//
// Created by KFB on 11/8/12.
// Copyright (c) 2012 com.kfb. All rights reserved.
//
#import <UIKit/UIKit.h>
#interface YouTubeView : UIViewController
{
IBOutlet UIWebView *thumbnailView;
}
#property (nonatomic, retain) IBOutlet UIWebView *thumbnailView;
#end
//
// YouTubeView.m
// KFBNewsroom
//
// Created by KFB on 11/8/12.
// Copyright (c) 2012 com.kfb. All rights reserved.
//
#import "YouTubeView.h"
#interface YouTubeView ()
#end
#implementation YouTubeView
#synthesize thumbnailView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = #"Monthly Video";
// Do any additional setup after loading the view from its nib.
// webView is a UIWebView, either initialized programmatically or loaded as part of a xib.
NSString *htmlString = #"<html><head><meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 280\"/></head><body style=\"background:#F00;margin-top:0px;margin-left:0px\"><div><object width=\"280\" height=\"218\"><param name=\"movie\" value=\"http://www.youtube.com/embed/videoseries?list=PL0B9BF37A24840E28&hl=en_US""></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"http://www.youtube.com/embed/videoseries?list=PL0B9BF37A24840E28&hl=en_US""type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"280\" height=\"218\"></embed></object></div></body></html>";
[thumbnailView loadHTMLString:htmlString baseURL:[NSURL URLWithString:#"http://www.youtube.com/playlist?list=PL0B9BF37A24840E28&feature=plcp"]];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end

To receive the notification that your device is rotated you need to set your project configuration to use also landscape modes. Then if you have your UIViewController class, you need to implement rotation to ignore everything besides portrait. In controller where you have your video, you just override it to accept landscape too.

Related

Why isn't my UIScrollView scrolling fully?

I dont know why my UIScroll view doesn't work. I am just learning iOS development and when I covered UIScrollView, I had problems in scrolling.
I created a new project just to check the scroll, but I had no luck. I'm using the iOS 6.1 simulator with Xcode 4.6.2.
This is my .h file:
#import <UIKit/UIKit.h>
#interface CDViewController12 : UIViewController<UIScrollViewDelegate>{
IBOutlet UIScrollView *scroll;
}
#end
and my .m file
#import "CDViewController12.h"
#interface CDViewController12 ()
#end
#implementation CDViewController12
- (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 from its nib.
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[scroll setScrollEnabled:YES];
scroll.contentSize = CGSizeMake(250, 2000);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc {
[scroll release];
[super dealloc];
}
#end
What am I doing wrong?
Try deactivating the auto layout property.
In the file inspector uncheck the box "Use AutoLayout"
hope this help!
Make sure the the size of the scroll view is not larger than the size of the parent view.

Call Void on First View Controller from Second View Controller in Xcode

I am using Xcode 4.6.2 and have created a new Tabbed Application using apples template. I have placed a UIWebView on my First View Controller and loaded http://google.co.uk into it. On my Second View Controller I have created a button that, when pressed, will load http://google.co.uk/images into the Web View on the first controller. It is this bit I am stuck on, here is my code so far:
FirstViewController.h
#import <UIKit/UIKit.h>
#interface FirstViewController : UIViewController {
IBOutlet UIWebView *mainWebView;
}
-(void)imagesURL;
#end
FirstViewController.m
#import "FirstViewController.h"
#interface FirstViewController ()
#end
#implementation FirstViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(#"First", #"First");
self.tabBarItem.image = [UIImage imageNamed:#"first"];
}
return self;
}
- (void)viewDidLoad
{
[mainWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://google.co.uk"]]];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)imagesURL {
[mainWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://google.co.uk/images"]]];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
SecondViewController.h
#import <UIKit/UIKit.h>
#import "FirstViewController.h"
#interface SecondViewController : UIViewController {
}
- (IBAction)imagesButton:(id)sender;
#end
SecondViewController.m
#import "SecondViewController.h"
#import "FirstViewController.h"
#interface SecondViewController ()
#end
#implementation SecondViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(#"Second", #"Second");
self.tabBarItem.image = [UIImage imageNamed:#"second"];
}
return self;
}
- (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.
}
- (IBAction)imagesButton:(id)sender {
FirstViewController *view1 = [[FirstViewController alloc] init];
[view1 imagesURL];
}
#end
At the moment, when I press the Images button on the Second View Controller and switch back to the first, nothing happens at all. The webpage doesn't load. its like the Void isn't being called. What am I doing wrong?
The problem is in this line here FirstViewController *view1 = [[FirstViewController alloc] init]; - that is creating an entirely new copy of your view controller, which is not the one you started with in your first tab.
I think you would benefit from following some Objective C tutorials, or perhaps one of the iOS programming courses on iTunes U so that if something like this occurs again you have some more background.
There are many ways to do what you are trying to do, but one of the most straightforward is to have your second view controller talk to the tab view controller displaying it to get the first view controller. There should be reasonable documentation about how to do this in the iOS UITabViewController docs.

implementing touches to drag various images with finger

I'm trying to be able to drag various images around using touches. So far, I'm trying to get it to work with just 1 image, but it's not working (i.e. I can't move the image with my finger). What am I doing wrong?
I have several files with the following code:
DragView.h
#interface DragView : UIImageView {
}
#end
DragView.m
#include "DragView.h"
#implementation DragView
- (void)touchesMoved:(NSSet *)set withEvent:(UIEvent *)event {
CGPoint p = [[set anyObject] locationInView:self.superview];
self.center = p;
}
#end
ViewController.h
#import <UIKit/UIKit.h>
#import "DragView.h"
#interface ViewController : UIViewController {
}
#property (nonatomic, strong) DragView *basketView;
#end
ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize basketView;
- (void)viewDidLoad
{
[super viewDidLoad];
basketView = [[DragView alloc]
initWithImage:[UIImage imageNamed:#"basket.png"]];
basketView.frame = CGRectMake(140, 340.2, 60, 30);
[self.view addSubview:basketView];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Try this:
basketView.userInteractionEnabled = YES;
Documentation says that:
New image view objects are configured to disregard user events by default. If you want to handle events in a custom subclass of UIImageView, you must explicitly change the value of the userInteractionEnabled property to YES after initializing the object.

Having trouble with mapkit usertrackingwithheading mode on iOS 6

I think I may have discovered a bug in the mapkit API for iOS 6, but since I still consider myself a rookie I thought I'd check here to see if anyone can point out something I may be doing wrong.
I have an app that I've been working on for a few weeks with a mapview in it and utilizing the MKUserTrackingButton to toggle tracking modes. On iOS 5 it was working fine but since upgrading to 6 it has weird behavior. When you put the mapview into The tracking mode that follows user with heading, it does fine if you are relatively stationary, but when you start moving in a car it drops out of the track with heading mode every time back to regular tracking mode. After many frustrating hours trying to figure it out I decided to make a new simple app with the bare minimum mapview and tracking to see if it was just my coding or possible bug. The new app does the same thing. I'm posting all the code below. Hopefully some one can help tell me if I'm doing something wrong or not.
Here's the app delegate header
// iTrackerAppDelegate.h
// iTracker
//
// Created by Victor Hudson on 9/22/12.
// Copyright (c) 2012 Victor Hudson. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TrackerViewController.h"
#interface iTrackerAppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) IBOutlet UIWindow *window;
#end
Here's the app delegate implementation
//
// iTrackerAppDelegate.m
// iTracker
//
// Created by Victor Hudson on 9/22/12.
// Copyright (c) 2012 Victor Hudson. All rights reserved.
//
#import "iTrackerAppDelegate.h"
#implementation iTrackerAppDelegate
#synthesize window = _window;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
TrackerViewController *trackerView = [[TrackerViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:trackerView];
[self.window setRootViewController:navController];
[[self window] makeKeyAndVisible];
return YES;
}
// the other app delegate methods are all empty so i left them out for brevity
#end
Here's my view controller. It has a nib with the worldView in it and a segmented switch for toggling map modes(plain, sat, and hybrid)
TrackerViewController.h
//
// TrackerViewController.h
// iTracker
//
// Created by Victor Hudson on 9/22/12.
// Copyright (c) 2012 Victor Hudson. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#interface TrackerViewController : UIViewController
#property (strong, nonatomic) IBOutlet MKMapView *worldView;
- (IBAction)toggleMapView:(id)sender;
#end
TrackerViewController.m
//
// TrackerViewController.m
// iTracker
//
// Created by Victor Hudson on 9/22/12.
// Copyright (c) 2012 Victor Hudson. All rights reserved.
//
#import "TrackerViewController.h"
#interface TrackerViewController ()
#end
#implementation TrackerViewController
- (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 from its nib.
// navigation item
[[self navigationItem] setTitle:#"iTracker"];
MKUserTrackingBarButtonItem *trackingButton = [[MKUserTrackingBarButtonItem alloc] initWithMapView:self.worldView];
[[self navigationItem] setRightBarButtonItem:trackingButton animated:YES];
self.worldView.userTrackingMode = 1;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)toggleMapView:(id)sender {
switch ([sender selectedSegmentIndex]) {
case 0:
{
[self.worldView setMapType:MKMapTypeStandard];
}break;
case 1:
{
[self.worldView setMapType:MKMapTypeSatellite];
}break;
case 2:
{
[self.worldView setMapType:MKMapTypeHybrid];
}break;
}
}
#end
As I said before all seems to work fine but the tracking with heading mode when you are moving very fast. I am running on an iPhone 4, and Ive tried the app with and without ARC to the same results. I would be grateful if someone can point out any mistakes I'm making or if they want to build the project and can confirm it is a bug.
Thanks in advance for any assistance ;-)
I'm currently investigating a similar behaviour in my app when going from ios5 to ios6.
There is a locationmanager created as a singleton as described in
cllocationmanager singleton
Furthermore in the mapview I'm using setusertrackingmode. In ios6 it jumps from MKUserTrackingModeFollowWithHeading to MKUserTrackingModeFollow back and forth. In ios5 it works fine with identical code.
It may be that the two locationmanagers are in conflict with each other as pointed out in
conflict between two locationmanagers

UITextView member variable is always NIL in my UIViewController [duplicate]

In my nib, I have a UITextView component.
In my UIViewController I have a UITextView member field and I have used IB to make sure that the two are connected (at least I think I did that by dragging from "Files Owner" and dropping it on the UITextView in IB and selecting my member variable).
Now, when I update the text via setText:, the UITextView still remains blank.
When I break into my code, the member variable (called textView) is nil.
So I am guessing I have not used IB correctly. How can I make sure that this variable is connected to the UITextView graphic element?
Here is the code
// My interface looks like
#import <UIKit/UIKit.h>
#interface DetailsController : UIViewController
{
UITextView *textView;
}
#property (nonatomic, retain) IBOutlet UITextView *textView;
#end;
// and the implementation
#import "DetailsController.h"
#implementation DetailsController
#synthesize textView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
// Custom initialization
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)viewDidUnload
{
[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);
}
// used pressed the "Done" button
- (IBAction)done
{
[self dismissModalViewControllerAnimated:YES];
}
- (void)setDetails: (NSString *)detail withQuote:(NSString *)quote
{
NSLog(#"%#", textView);
[textView setText:detail];
}
#end
save nib file after connecting outlet, build project and run, it should work if it's connected
I can't see agere you are calling setText, but I think that you try to do it in the initializer. GUI code should not be done before the viewDidLoad in the case of using XIB's or loadView if you make your GUI programatically, or the other viewWill/viewDid... methods.
The reason is because the views are not loaded before they are actually needed, it is called lazy loading. You should Google that for more info.