AGImagePickerController *imagePickerController = [[AGImagePickerController alloc] initWithFailureBlock:^(NSError *error) {
if (error == nil)
{
NSLog(#"User has cancelled.");
[self dismissModalViewControllerAnimated:YES];
} else
{
NSLog(#"Error: %#", error);
// Wait for the view controller to show first and hide it after that
double delayInSeconds = 0.5;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[self dismissModalViewControllerAnimated:YES];
});
}
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
} andSuccessBlock:^(NSArray *info) {
NSLog(#"Info: %#", info);
[self dismissModalViewControllerAnimated:YES];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
}];
popover = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];
[popover presentPopoverFromRect:CGRectMake(0.0, 0.0, 400.0, 400.0)
inView:self.view.window
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
was able to present it, but, even I change the size its still the same, and when I pressed the DONE button, it removes my View controller not the imagepicker. Help please. I present it in a popover cause I think that, thats's why its slow it because imagepicker should be present with popover for iPad.
Are you implementing the AGImagePickerController delegates?
- (void)agImagePickerController:(AGImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info;
There you can dismiss your UIPopoverController.
resize set it this way:
[popoverController setPopoverContentSize:CGSizeMake(1024, 500)];
then in your andSuccessBlock and other part you used:
[self dismissModalViewControllerAnimated:YES];
should be
[popoverController dismissPopoverAnimated:YES];
That's why ViewController is being dismissed or removed from the view, because it is being dismissed the wrong way.
Related
Ok so here is a picture of my basic setup
Now this may not be the best way to set it all up but I did what I could with the knowledge I had to get the effect I wanted. Now my problem is originates in view 1 but only happens if you do this: Start at the menu click view 2,3 or 4 to go to that view then go to view 1 using the tabbar button now at this screen you would click the get pictures button which has the code below in its viewcontroller to show the image picker. Now the problem comes is if you go back at this point it takes you to the tabbarview that you clicked from the menu whether that was 2,3,or 4. It goes back fine if you clicked view 1 from the menu
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.selectedPhotos = [NSMutableArray array];
__block AGViewController *blockSelf = self;
ipc = [[AGImagePickerController alloc] initWithDelegate:self];
ipc.didFailBlock = ^(NSError *error) {
NSLog(#"Fail. Error: %#", error);
if (error == nil) {
[blockSelf.selectedPhotos removeAllObjects];
NSLog(#"User has cancelled.");
[blockSelf dismissViewControllerAnimated:YES completion:nil];
} else {
// We need to wait for the view controller to appear first.
double delayInSeconds = 0.5;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[blockSelf dismissViewControllerAnimated:YES completion:nil];
});
}
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
};
ipc.didFinishBlock = ^(NSArray *info) {
[blockSelf.selectedPhotos setArray:info];
NSLog(#"Info: %#", info);
//add all selected photos to the claim
[blockSelf setClaimPhotos:info];
[blockSelf dismissViewControllerAnimated:YES completion:nil];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
};
}
- (void)openAction:(id)sender
{
// Show saved photos on top
ipc.shouldShowSavedPhotosOnTop = NO;
ipc.shouldChangeStatusBarStyle = YES;
ipc.selection = self.selectedPhotos;
ipc.maximumNumberOfPhotosToBeSelected = 5;
// Custom toolbar items
AGIPCToolbarItem *selectAll = [[AGIPCToolbarItem alloc] initWithBarButtonItem:[[UIBarButtonItem alloc] initWithTitle:#"+ Select All" style:UIBarButtonItemStyleBordered target:nil action:nil] andSelectionBlock:^BOOL(NSUInteger index, ALAsset *asset) {
return YES;
}];
AGIPCToolbarItem *flexible = [[AGIPCToolbarItem alloc] initWithBarButtonItem:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil] andSelectionBlock:nil];
AGIPCToolbarItem *deselectAll = [[AGIPCToolbarItem alloc] initWithBarButtonItem:[[UIBarButtonItem alloc] initWithTitle:#"- Deselect All" style:UIBarButtonItemStyleBordered target:nil action:nil] andSelectionBlock:^BOOL(NSUInteger index, ALAsset *asset) {
return NO;
}];
ipc.toolbarItemsForManagingTheSelection = #[selectAll, flexible, flexible, deselectAll];
[self presentViewController:ipc animated:YES completion:nil];
}
(the open action is what is tied to the button on the vc)
I really need help on this one as Ive been stuck on this issue all week and have been trying all types of dissmiss view controller ect ect.
The problem was due a custom class on the TabBarController that was causing an unexpecting behavior with SelectedIndex property.
I have used below code for IO6 and below to force rotate:
-(void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
UIApplication* application = [UIApplication sharedApplication];
if (application.statusBarOrientation != UIInterfaceOrientationPortrait)
{
UIViewController *c = [[UIViewController alloc]init];
[c.view setBackgroundColor:[UIColor redColor]];
[self.navigationController presentViewController:c animated:NO completion:^{
[self.navigationController dismissViewControllerAnimated:NO completion:^{
}];
}];
}
}
But it is not working correctly on IOS7, it rotate view controller but again set blank view on screen...
Can you help me to solve this issue in IOS 7...
Change this line:
[self.navigationController dismissViewControllerAnimated:NO completion:^{
}];
To this:
[self.navigationController dismissViewControllerAnimated:YES completion:^{
}];
I am using presentViewController:imagePickerController to display the UIImagePickerController. For some reason when I end up dismissing that controller my original navigation controller looses it's stack and my application is back at the root view controller.
I am logging self.navigationController.viewControllers and I can see that after I run the presentViewController:imagePickerController line my navigation controller looses all of its controllers except for the root controller.
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
imagePickerController.sourceType = sourceType;
imagePickerController.delegate = self;
imagePickerController.navigationBarHidden = YES;
self.imagePickerController = imagePickerController;
DLog(#"self.navigationController:%#",self.navigationController.viewControllers);
[self.navigationController presentViewController:imagePickerController animated:YES completion:^{
DLog(#" after presenting self.navigationController:%#",self.navigationController.viewControllers);
}];
////Closing it
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
DLog(#"self.navigationController:%#",self.navigationController.viewControllers);
[self.navigationController dismissViewControllerAnimated:YES completion:^{
}];
}
/////Where my NC is set up
OFMainViewController *mainController = [[OFMainViewController alloc]init];
mainController.managedObjectContext = self.managedObjectContext;
navigationController = [[UINavigationController alloc]initWithRootViewController:mainController];
[self.window setRootViewController:navigationController];
Instead of using self.navigationController use self for both dismissing and calling the imagepickerviewcontroller.
You should present imagePickeController on self instead of self.navigationController.
[self presentViewController:imagePickerController animated:YES completion:^{
DLog(#" after presenting self:%#",self.navigationController.viewControllers);
}];
And dissmiss it accordingly:
////Closing it
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
DLog(#"self.navigationController:%#",self.navigationController.viewControllers);
[self dismissViewControllerAnimated:YES completion:^{
}];
}
EDIT : I am using UIStoryBoard.
I have presented like this:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; //| UIImagePickerControllerSourceTypeSavedPhotosAlbum ;
imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage,nil];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
imagePicker.allowsEditing = YES;
[self.navigationController presentViewController:imagePicker animated:YES completion:^{
}];
}
}
Now when dissmissed
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = info[UIImagePickerControllerEditedImage];
NSLog(#"Image : %#",image);
[self dismissViewControllerAnimated:YES completion:^{
}];
}
Now view becomes like this as shown in fiqure :
EDIT : view gets pushed up to 20px when dissmissed.
EDIT : This is only in iOS 6.0 only
The reason was i was setting frame of view controller which is in protrait mode as its previous view was in landscape mode.
self.view.bounds = CGRectMake(0,0,...,...);
Whenever imagepicker dissmiss got called it moved to original position as mentioned.
Now changed in structure for orientation without setting self.view frame externally solved my problem.
If that blue part of view is custom UIView then you should check the auto resizing mask for that view. You will find the problem.
I have similar problem, and in my case 20 pixels was the status bar height.
So, try to set status bar visibility to NO before showing imagePicker and YES when it finished (in delegate methods).
something like this:
[UIApplication sharedApplication].statusBarHidden = YES;
[self.navigationController presentViewController:imagePicker animated:YES completion:^{
}];
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// ... your code here
[UIApplication sharedApplication].statusBarHidden = NO;
[self dismissViewControllerAnimated:YES completion:^{
}];
}
I had similar issue on iOS 8.2. After picking video using UIImagePickerController the frame is increased by 20px, top area of view controller is looking good, but the bottom is cut off.
The solution is:
-(void)openPicker {}
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
//configure image picker here
[self presentViewController:picker animated:YES completion:NULL];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:#selector(showStatusBar) userInfo:nil repeats:NO];
[picker dismissViewControllerAnimated:YES completion:NULL];
}
-(void)showStatusBar {
dispatch_async(dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
});
}
I have a UIViewController with a UITableView in it. I add a UIView as a subview on top of that. When I press one of the UIButtons on the subview, there is a noticeable lag. How do I make it faster?
See video: http://www.youtube.com/watch?v=KWy6NrZUeqA&feature=youtu.be
- (IBAction)tweetThat:(id)sender {
[MBProgressHUD showHUDAddedTo:self.socialMediaView animated:YES];
dispatch_queue_t queueOne=dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_sync(queueOne, ^{
NSString *tweetBody=#"BLABLABLATweet";
if ([TWTweetComposeViewController canSendTweet])
{
TWTweetComposeViewController *tweetSheet =
[[TWTweetComposeViewController alloc] init];
[tweetSheet setInitialText:tweetBody];
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUDForView:self.controllerView animated:YES];
[self presentModalViewController:tweetSheet animated:YES];
});
}
});
}
I've used the dispatch method you tried above, but with a few changes. It has really made the experience a lot better. "loadingView" is as named, just a loading view that displays before the tweet view comes up.
loadingView.hidden = NO;
[loadingView setNeedsDisplay];
if ([TWTweetComposeViewController canSendTweet])
{
double delayInSeconds = 0.5;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
TWTweetComposeViewController *tweet = [[TWTweetComposeViewController alloc]init];
[tweet setInitialText:#"I'm using a new app called TickTalk to help my speaking cadence. Check it out!"];
[tweet addURL:[NSURL URLWithString:#"http://www.ticktalkapp.com"]];
TWTweetComposeViewControllerCompletionHandler
completionHandler =
^(TWTweetComposeViewControllerResult result) {
switch (result)
{
case TWTweetComposeViewControllerResultCancelled:
NSLog(#"Twitter Result: canceled");
break;
case TWTweetComposeViewControllerResultDone:
NSLog(#"Twitter Result: sent");
break;
default:
NSLog(#"Twitter Result: default");
break;
}
loadingView.hidden = YES;
[self dismissModalViewControllerAnimated:YES];
};
[tweet setCompletionHandler:completionHandler];
[self presentModalViewController:tweet animated:YES];
});
}
else
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Sorry" message:#"Your device is not setup to tweet" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
loadingView.hidden = YES;
}
change your dispatch_sync to dispatch_async. what is the point of dispatching to the background if you are going to lock up the UI until it returns.
The lag is from TWTweetComposeViewController. There is nothing you can do about it because its a system optimization. You'll probably notice the second and third times you hit the button the lag it gone.