I am trying to display a QLpreviewcontroller on a UIVIewcontroller.
-(void)showPreview{
if(!_previewController){
_previewController = [[QLPreviewController alloc] init];
_previewController.dataSource = self;
_previewController.delegate = self;
}
// There will always be one item here
_previewController.currentPreviewItemIndex = 0;
[_previewController setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentViewController:_previewController animated:YES completion:nil];
}
the previecontroller is displayed but the transition is not animated. it just appears without any animation.
Related
I have a problem when trying to display the GKMatchmakerViewController on my game view.
Normally I create a multiplayer match programmatically by auto-matching 2 opponents, and that works fine.
But when I try to display the standard Game Center Matchmaking view, it dismisses my game view and pushes me back to the menu.
Menu View -> Game View.
I think the problem might be that my menu view acts as my main view and all other views are removed when the Game Center view is displayed (since only one view controller can be shown at the time).
am I setting up my view hierarchy wrong? How should it be done so my Game View wont be dismissed when displaying the Game Center view?
EDIT - updated with code that calls the GKMatchMakerViewController
GameviewController with method that is called when I want to display the Game Center match making controller
- (void)presentCustomVSBattle {
ourRandom = arc4random();
[self setGameState:kGameStateWaitingForMatch];
AppDelegate * delegate = (AppDelegate *) [UIApplication sharedApplication].delegate;
[[GCHelper sharedInstance] findCustomMatchWithMinPlayers:2 maxPlayers:2 viewController:delegate.viewController delegate:self];
}
// This method is called in GCHelper.m
- (void)findCustomMatchWithMinPlayers:(int)minPlayers maxPlayers:(int)maxPlayers viewController:(UIViewController *)viewController delegate:(id<GCHelperDelegate>)theDelegate {
if (!gameCenterAvailable) return;
matchStarted = NO;
self.match = nil;
self.presentingViewController = viewController;
delegate = theDelegate;
if (pendingInvite != nil) {
[presentingViewController dismissModalViewControllerAnimated:NO];
GKMatchmakerViewController *mmvc = [[[GKMatchmakerViewController alloc] initWithInvite:pendingInvite] autorelease];
mmvc.matchmakerDelegate = self;
[presentingViewController presentViewController:mmvc animated:YES completion:nil];
self.pendingInvite = nil;
self.pendingPlayersToInvite = nil;
}
else {
[presentingViewController dismissModalViewControllerAnimated:NO];
GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease];
request.minPlayers = minPlayers;
request.maxPlayers = maxPlayers;
request.playersToInvite = pendingPlayersToInvite;
GKMatchmakerViewController *mmvc = [[[GKMatchmakerViewController alloc] initWithMatchRequest:request] autorelease];
mmvc.matchmakerDelegate = self;
[presentingViewController presentViewController:mmvc animated:YES completion:nil];
self.pendingInvite = nil;
self.pendingPlayersToInvite = nil;
}
}
In your case, the dismissView Controller calls look unnecessary, try getting rid of them :)
Popover appears properly when I click on button.
When orientation changes then it disappears & leave a black topbar.
Below is the reference image.
Can anyone suggest, why it is happening?
My Code:
EBFirstViewController *firstViewController = [[EBFirstViewController alloc]init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
navigationController.delegate = self;
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:navigationController];
self.popoverController = popover;
popoverController.delegate = self;
[popoverController setPopoverContentSize:CGSizeMake(320.0f, 527.0f)];
[popoverController presentPopoverFromRect:settingsBtn.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
For That following code help to solve your problem.
- (void)application:(UIApplication *)application willChangeStatusBarOrientation:(UIInterfaceOrientation)newStatusBarOrientation duration:(NSTimeInterval)duration {
// a cheat, so that we can dismiss all our popovers, if they're open.
if (ObjPopover) {
// if we're actually showing the menu, and not the about box, close out any active menu dialogs too
if (menuPopoverVC && menuPopoverVC == ObjPopover.contentViewController)
[menuPopoverVC.popoverController dismissPopoverAnimated:YES];
[menuPopoverPC dismissPopoverAnimated:YES];
menuPopoverPC = nil;
}
}
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
// the user (not us) has dismissed the popover, let's cleanup.
ObjPopover = nil;
}
When click button, a popoverView embedded in NavigationView appear.
My code is as follows:
-(IBAction)myStuffPOP:(id)sender
{
if(myStuffListViewController ==nil)
{
myStuffListViewController = [[MyStuffListViewController alloc] init];
}
UINavigationController *navcontroller=[[[UINavigationController alloc] initWithRootViewController:myStuffListViewController] autorelease];
// Here we create popover controller.
mystuffPopoverView = [[UIPopoverController alloc] initWithContentViewController:navcontroller] ;
CGRect popoverRect = [self.view convertRect:[sender frame] fromView:[sender superview]];
popoverRect.size.width = MIN(popoverRect.size.width, 100);
popoverRect.size.height = 40;
[mystuffPopoverView presentPopoverFromRect:popoverRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
[navcontroller setNavigationBarHidden:NO];
}
In NavigationView of PopoverView :
1st subView ---> 2nd SubView ---> 3rd Subview
If I touch 3rd SubView, PopoverView disappears.
My Question is :
When I click button again, I wanna to see lastest View - 3rd SubView not 1st SubView.
Declare UINavigationController *navcontroller; in .h file
Create only onсe navcontroller with your root view controller,
in viewDidLoad method, for example.
- (void)viewDidLoad {
myStuffListViewController = [[MyStuffListViewController alloc] init];
navcontroller=[[UINavigationController alloc] initWithRootViewController:myStuffListViewController]; }
Show UIPopoverController with exist navigation stack
-(IBAction)myStuffPOP:(id)sender {
//Here we create popover controller.
mystuffPopoverView = [[UIPopoverController alloc] initWithContentViewController:navcontroller] ;
CGRect popoverRect = [self.view convertRect:[sender frame] fromView:[sender superview]];
popoverRect.size.width = MIN(popoverRect.size.width, 100);
popoverRect.size.height = 40;
[mystuffPopoverView presentPopoverFromRect:popoverRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];
[navcontroller setNavigationBarHidden:NO]; }
Don't forget to release objects
- (void)dealloc {
[myStuffListViewController release];
[navcontroller release];
}
No need to create UINavigationController every time. Save it the same way as MyStuffListViewController
if ( myNavigationController == nil )
myNavigationController = [[[UINavigationController alloc] initWithRootViewController:myStuffListViewController] autorelease];
I have a UIPopoverController that is presented from a button on my UIViewController but when I tap on any part of the view that is not the popover it is not hiding?
The buttons that present this popover are created dynamically, you'll see that referenced in the code below:
-(IBAction)showModifiers:(id)sender{
[self.popoverController dismissPopoverAnimated:YES];
UIView *theSuperview = self.view;
CGPoint touchPointInSuperview = [sender locationInView:theSuperview];
UIView *touchedView = [theSuperview hitTest:touchPointInSuperview withEvent:nil];
currentPopoverTag = [touchedView tag];
NSLog(#"Show Modifiers %i %i", [touchedView tag], currentPopoverTag);
RepZioCoreDataAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
if (appDelegate.popoverController)
[appDelegate.popoverController dismissPopoverAnimated:YES];
self.modifierListPopoverViewController = nil;
ModifierListCollection *collection = [self.modifierLists objectAtIndex:[touchedView tag]-100];
ModifierList *modifierList = [self getModifierList:collection.ModifierListID];
self.modifierListPopoverViewController =
[[[ModifierListPopoverViewController alloc] initWithModifierList:modifierList withManufacturerID: self.manufacturerID] autorelease];
self.modifierListPopoverViewController.delegate = self;
self.popoverController = [[[UIPopoverController alloc] initWithContentViewController:modifierListPopoverViewController] autorelease];
[self.popoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
I realize it's unlikely, but does your ModifierListPopoverViewController class set its modalInPopover property to YES? (the default is NO, which should give you the behavior you're looking for).
It seems that some view tackles the touch event.
I am looking for some help for a program I am developing. Basically, it contains two views. The first view has a button and a action related to it leads me to my next view where there is a scroll view for three pages ( as in the PageControl sample given by apple.) I am using navigation controller to push the view from the first view to the second view. But on pushing I am not able to scroll the page or using page control or anything. It just comes a normal view. The code is same as pageControl code and it works fine as a separate module. But when I want to integrate this pageControl code with a first view and a click button it doesn't work. Please help.
//this function is an action set against a button in the rootviewcontroller.
-(IBAction) viewScrollPages:(id)sender{
UIViewController *controller = [[MyViewController alloc] initWithPageNumber:0];
[self.navigationController pushViewController:controller animated:NO];
[controller release];
}
- (id)initWithPageNumber:(int)page {
if (self = [super initWithNibName:#"MyViewController" bundle:nil]) {
pageNumber = page;
}
return self;
}
- (void)viewDidLoad {
NSMutableArray *controllers = [[NSMutableArray alloc] init];
for (unsigned i = 0; i < kNumberOfPages; i++) {
[controllers addObject:[NSNull null]];
}
self.viewControllers = controllers;
[controllers release];
// a page is the width of the scroll view
scrollView.pagingEnabled = YES;
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * kNumberOfPages, scrollView.frame.size.height);
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;
scrollView.scrollsToTop = NO;
scrollView.delegate = self;
pageControl.numberOfPages = kNumberOfPages;
pageControl.currentPage = 0;
// pages are created on demand
// load the visible page
// load the page on either side to avoid flashes when the user starts scrolling
[self loadScrollViewWithPage:0];
[self loadScrollViewWithPage:1];
pageNumberLabel.text = [NSString stringWithFormat:#"Page %d", pageNumber + 1];
self.view.backgroundColor = [MyViewController pageControlColorWithIndex:pageNumber];
[super viewDidLoad];
}
It sounds like your pushing a normal view that is a subview of the scrollview instead of pushing the scrollview itself.