Is it possible to use pickerview in cocos2d? - iphone

Duplicate:
How can i use picker view in iphone application using cocos2d ?
Is it possible to use pickerview in iphone application using cocos2d ? If possible then can i do that in my application.Where i can get this information.If not then what are the other solution for doing this in pickerview.

I haven't looked into cocos2d at all, but I assume that if you still have access to the UIKit fameworks within your app you should be able to create an instance of UIPickerView.
However, I'm not sure you'll be able to used it the way you're intending without some subclassing or writing your own. The picker view is intended to be used by the user to pick an item from a selection, not to be automatically spun by the app...

Yes you can use UIKit controls in Cocos2DIPhone.
You just need to attach them directly to the application window.
There are examples in the docs and on the cocos2d message board. Riq is excellent with questions/feedback on the message board there as well.

I have used the UIImagePicker controller in my application using the steps below:
// 1 - instantiate your picker (in my case UIImagePicker):
pickerController = [[UIImagePickerController alloc] init];
pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
pickerController.delegate = self;
// 2 - add the picker view as a subview of the actual scene
[[Director sharedDirector] openGLView] addSubview:pickerController.view];
It worked for me but the transition is not animated.

Related

Using popover control in iPhone

pop = [[UIPopoverController alloc] initWithContentViewController:popoverView];
pop.delegate = self; //optional
CGSize size = CGSizeMake(300, 100); // size of view in popover…V2
pop.popoverContentSize = size;
[pop presentPopoverFromRect:control.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
Youtube link: http://www.youtube.com/watch?v=1iykxemuxbk
It works fine in simulator, but crashes when running on iPhone.
I can easily get so many articles to implement on iPad, but on iPhone couldn't find a fruitful one. Plz help
UIPopOverController isn't available for iPhone. ONLY iPad.
UIPopOverController will not work for iPhone it will work on Ipad only
If you want to simulate a popover look-alike (e.g. Facebook app), on the iPhone, you will have to code it from scratch using UIViews and custom graphics.
As others said, the popover API is iPad-only.
A popover-like open source project that works on iPhone:
here it is
Try using WEPopover framework. Here is the link https://github.com/werner77/WEPopover
If you really want to use popover in iphone then try this library. This is pretty cool. I integrated with my ios app.
Custom popover controller for iphone

iphone cocos2d iAd problem

we have an application built using cocos2d, the first class (scene) called from the app delegate is the levels class which then calls the game class (scene) according to user choice. where should i write my iAd code and how ? any help please.
My suggestion would be to look at AdWhirl, which would make your ads decoupled from the ad network.
More can be found below.
https://www.adwhirl.com/home/dev
My understanding is that you can not put UIViews directly into CCLayer, or CCScene (i hope those are the names), you will have to shrink your scene in order to put the iAd beside your Cocos2d view.
To implement iAd add the import
#import <iAd/ADBannerView.h>
If you initialize iAd in the AppDelegate, it will displayed everywhere.
This is very easy to achieve.
ADBannerView* iAdView = [[ADBannerView alloc] initWithFrame:CGRectZero];
iAdView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
[[[CCDirector sharedDirector] openGLView] addSubview:iAdView];
For more information, look at apples programming guide http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/iAd_Guide/Introduction/Introduction.html
I recently wrote a post about this issue (integrating iAd in a Cocos2d-x game) in my blog. Take a look and ask me if you have any questions.

UIImagePickerControllerSourceTypeCamera crashes in IPHONE Simulator?

Is it a known issue that if you try to test your UIImagePickerController using the Camera as a source type then the simulator will crash?
I have the following code:
self.imgPicker = [[UIImagePickerController alloc] init];
self.imgPicker.allowsEditing = NO;
self.imgPicker.delegate = self;
[self.imgPicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentModalViewController:self.imgPicker animated:YES];
[imgPicker release];
Running this in simulator, I get an objc-exception-throw error on the stack # -[UIImagePickerController setSourceType:].
Now if I set the source type to the Photo Library though, everything runs smoothly and fine? What's the deal?
Simulator doesn't have the camera and can't simulate to take a picture (it would have been nice to use the isight but Apple has not been so kindly). However Your code is not safe because, for example, old ipod touch doesn't have a camera and in this case your app will crash on this device.
As Apple suggest in UIImagePickerController documentation:
To use an image picker controller
containing its default controls,
perform these steps:
1.Verify that the device is capable of picking content from the
desired source. Do this calling the
isSourceTypeAvailable: class method,
providing a constant from the
“UIImagePickerControllerSourceType”
enum.
2.Check which media types are available, for the source type you’re
using, by calling the
availableMediaTypesForSourceType:
class method. This lets you
distinguish between a camera that can
be used for video recording and one
that can be used only for still
images.
3.Tell the image picker controller to adjust the UI according to the
media types you want to make
available—still images, movies, or
both—by setting the mediaTypes
property.
4.Present the user interface by calling the
presentModalViewController:animated:
method of the currently active view
controller, passing your configured
image picker controller as the new
view controller.
5.When the user taps a button to pick a newly-captured or saved image
or movie, or cancels the operation,
dismiss the image picker using your
delegate object. For newly-captured
media, your delegate can then save it
to the Camera Roll on the device. For
previously-saved media, your delegate
can then use the image data according
to the purpose of your app.
So you have to call isSourceTypeAvailable and set your sourceType consistently.

iOS4 ABNewPersonViewController Loses Data Entered when attempting to add a Photo iPhone 4

I have implemented a basic add contact feature to an iOS 4 application. Following the documentation from Apple, I have created a navigation controller, and set its root view to the ABNewPersonViewController. I have implemented the delegate as well. The basic mechanics all work.
The problem I am having is when you add a photo to the new person that is very large (taking a photo or picking one from the library), the ABNewPersonViewController form returns empty when the camera controls are dismissed. No photo is in the add photo box either. If I pick a small image (say a screenshot from the iPhone), everything works. I can see from the debug output: Received memory warning. Level=1
Has anyone else run into this? Is there a way to set the photo quality to a lower setting for the ABNewPersonViewController? Any help appreciated.
ABNewPersonViewController *abNewPersonView = [[ABNewPersonViewController alloc] init];
abNewPersonView.newPersonViewDelegate = self;
UINavigationController *newNavigationController = [UINavigationController alloc];
[newNavigationController initWithRootViewController:abNewPersonView];
[self presentModalViewController:newNavigationController animated:YES];
[abNewPersonView release];
[newNavigationController release];
If ABNewPersonViewController does not handle memory warnings correctly, file a bug with apple.

iPhone: taking a picture programmatically

I'm trying to use the UIImagePickerController interface from OS 3.1, with the cameraOverlayView and takePicture, but I've clearly failed to understand how this works, and so I'm not getting the behaviour I want.
What I want to do is open the camera and take a picture automatically without having to having the user interact with the picker or edit the image. So I subclass UIImagePickerController (similar to the example in http://github.com/pmark/Helpful-iPhone-Utilities/tree/master/BTL%20Utilities/) and turn off all of the controls:
- (void)displayModalWithController:(UIViewController*)controller animated:(BOOL)animated {
self.sourceType = UIImagePickerControllerSourceTypeCamera;
self.showsCameraControls = NO;
self.navigationBarHidden = YES;
self.toolbarHidden = YES;
// Setting the overlay view up programmatically.
ipView = [[ImagePickerView alloc] init];
self.cameraOverlayView = ipView;
[controller presentModalViewController:self animated:NO];
}
In the overlayView, I've managed to force the takePicture method of UIImagePickerController to fire (I know this, because I can NSLog it, and I hear the sound of the camera taking a picture). The overlayView shows up just fine. However, the delegate method didFinishPickingMediaWithInfo: never gets called, and imagePickerControllerDidCancel doesn't get called either.
So, how do I either get the delegate methods to get called, or save the picture by overriding the takePicture method? (I have no idea how to capture the picture data here, and Google seems to have failed me). I can't help feeling that I've failed to understand how the guts of UIImagePickerController works, but the docs aren't overly helpful:
e.g.:
"You can provide a custom overlay view to display a custom picture-taking interface and you can initiate the taking of pictures from your code. Your custom overlay view can be displayed in addition to, or instead of, the default controls provided by the image picker interface."
or from showCameraControls:
"If you set this property to NO and provide your own custom controls, you can take multiple pictures before dismissing the image picker interface." - How do I dismiss the picker interface?
Note: the delegate is set properly in IB, so that's not the problem.
Thanks for any help you can provide!
I've found that you just have to wait "long enough" before calling takePicture, or it just silently fails. I don't have a good answer for how to determine the minimum value of "long enough" that will always work, but if you set a timer and wait five or ten seconds you should be okay. It would be nice if it returned some kind of an "I'm not ready to take a picture yet, sorry" error either directly from takePicture or through the delegate, but as far as I know it doesn't.
As an update to my own question: It turns out that I was trying to use takePicture too early. When I moved the action to a button on the overlay and sent takePicture from that button (once the picker was presented modally), the delegate methods fired as they should. I don't know if what I wanted is achievable - taking the image without having to press that button, automatically - but if it is, it will probably have to be done by sending takePicture sometime after I was trying to use it.
-(void)imageMethod:(id)sender{
imagePickerController = [[UIImagePickerController alloc]init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePopover=[[UIPopoverController alloc]initWithContentViewController:imagePickerController];
[imagePopover presentPopoverFromRect:importButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
}