disable rotation in single View iOS - ios

I am trying to disable rotation for just a single viewController in iOS, i have see some questions asked for auto rotate but none for this.
I want to lock the orientation that View B opens into For ex: opens in landscape, it can only be landscape, or opens in portrait, it can only be portrait. While still allowing view A to be whatever orientation it wants.
EDIT
\n
This is how i call view B
[self.mediaFocusController showImageFromURL:url fromView:self.view withThumb:thumbUrl];
This is how it enters:
if (self.targetViewController) {
[self willMoveToParentViewController:self.targetViewController];
if ([UIView instancesRespondToSelector:#selector(setTintAdjustmentMode:)]) {
self.targetViewController.view.tintAdjustmentMode = UIViewTintAdjustmentModeDimmed;
[self.targetViewController.view tintColorDidChange];
}
[self.targetViewController addChildViewController:self];
[self.targetViewController.view addSubview:self.view];
if (self.snapshotView) {
[self.targetViewController.view insertSubview:self.snapshotView belowSubview:self.view];
[self.targetViewController.view insertSubview:self.blurredSnapshotView aboveSubview:self.snapshotView];
}
}
else {
// add this view to the main window if no targetViewController was set
if ([UIView instancesRespondToSelector:#selector(setTintAdjustmentMode:)]) {
self.keyWindow.tintAdjustmentMode = UIViewTintAdjustmentModeDimmed;
[self.keyWindow tintColorDidChange];
}
[self.keyWindow addSubview:self.view];
if (self.snapshotView) {
[self.keyWindow insertSubview:self.snapshotView belowSubview:self.view];
[self.keyWindow insertSubview:self.blurredSnapshotView aboveSubview:self.snapshotView];
}
}
I have NavigationController set up but this view is different

Trying this code (I found that in https://stackoverflow.com/a/17377221/2040992):
- (BOOL)shouldAutorotate
{
id currentViewController = self.topViewController;
if ([currentViewController isKindOfClass:[DetailViewController class]])
return NO;
return YES;
}

Related

SWRevealViewController rightViewController disable the opening

I created the side menu structure using the SWReveal view controller.What I want to do is to cancel the opening of the right-side view controller on some pages.I have researched and found something like this:
- (BOOL)revealControllerPanGestureShouldBegin:(SWRevealViewController *)revealController
if([revealController.frontViewController isKindOfClass:[UINavigationController class]]){
UINavigationController *navController = (UINavigationController *)revealController.frontViewController;
UIViewController *lastViewController = navController.viewControllers.lastObject;
if([lastViewController isKindOfClass:[DetailViewController class]] ||
[lastViewController isKindOfClass:[TableDateViewController class]] ||
[lastViewController isKindOfClass:[MapViewController class]])
{
return NO; // I do not want to open it for the view controllers I want
}
}
return YES;
}
This worked for me,but it also affected the opening of the left page.There is no problem with the touch action(tap gesture),but this applies to the pan gesture.I mean the pan gesture does not work for the view controller I want to run.I want to work correctly for some view controller,but I do not want to affect the left side.
I added the right toggle like this:
-(void)sideRightMenuLoad{
[((PersonelViewController *)[self.navigationController.viewControllers objectAtIndex:0]).view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
SWRevealViewController *revealViewController = self.revealViewController;
if(revealViewController){
[self.sideRightBarButton setTarget:self.revealViewController];
[self.sideRightBarButton setAction:#selector(rightRevealToggle:)];
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
}
This code needs to work to open the right-side page:
[self performSegueWithIdentifier:SWSegueRightIdentifier sender:nil];
I tried to run it when I wanted it, but it did not work.
I am waiting for help in this regard.Thank you.
You have to check the pan gesture's direction:
- (BOOL)revealControllerPanGestureShouldBegin:(SWRevealViewController *)revealController {
if ([revealController.panGestureRecognizer velocityInView:revealController.view].x < 0) {
// pan direction left, should open right side
// ...
return NO;
}
return YES;
}
SWIFT 4
func revealControllerPanGestureShouldBegin(_ revealController: SWRevealViewController!) -> Bool {
let point = revealController.panGestureRecognizer().location(in: self.view)
if revealController.frontViewPosition == FrontViewPosition.left && point.x < 50.0 {
print("YES YES YES YES RRRRIIIIGGGGHHHHTTTT")
return false
}
else if revealController.frontViewPosition == FrontViewPosition.right {
print("YES YES YES YES LLLLEEEEFFFFTTTT")
return true
}
return false
}

How can I remove TabBar if I enter one given ViewController

Setting:
Assume I have 2 TableViewControllers(All in their own NavigationControllers), which contain TypeA&B items correspondingly.
In any TableView, If I tap "+" button, it will segue to a Add[?]ItemViewController("?" is The Type of Item: A or B).So normally, even if I already in the AddView, I can also switch to another View By tapping Tab Bar Icon, right?
SO How can I inhibit user to switch if they already entered one AddView?
Use the Swift code? or just change the storyboard structure?
Here is the Structure of Main.storyboard:
We've done exactly the same in our application. To hide the default
TabBar, simply override the hidesBottomBarWhenPushed method in your
parent view controller (or in every view controller in your App)
#pragma mark - Overriden UIViewController methods
- (BOOL)hidesBottomBarWhenPushed {
return YES;
}
another Solution
You can also Hide Tab bar
// pass a param to describe the state change, an animated flag and a completion block matching UIView animations completion
- (void)setTabBarVisible:(BOOL)visible animated:(BOOL)animated completion:(void (^)(BOOL))completion {
// bail if the current state matches the desired state
if ([self tabBarIsVisible] == visible) return;
// get a frame calculation ready
CGRect frame = self.tabBarController.tabBar.frame;
CGFloat height = frame.size.height;
CGFloat offsetY = (visible)? -height : height;
// zero duration means no animation
CGFloat duration = (animated)? 0.3 : 0.0;
[UIView animateWithDuration:duration animations:^{
self.tabBarController.tabBar.frame = CGRectOffset(frame, 0, offsetY);
} completion:completion];
}
// know the current state
- (BOOL)tabBarIsVisible {
return self.tabBarController.tabBar.frame.origin.y < CGRectGetMaxY(self.view.frame);
}
// illustration of a call to toggle current state
- (IBAction)pressedButton:(id)sender {
[self setTabBarVisible:![self tabBarIsVisible] animated:YES completion:^(BOOL finished) {
NSLog(#"finished");
}];
}
another Solution
You can set the UIViewController.hidesBottomBarWhenPushed instead:
DetailViewController *detailViewController = [[DetailViewController alloc] init];
detailViewController.hidesBottomBarWhenPushed = YES;
[[self navigationController] pushViewController:detailViewController animated:YES];

Full Screen Custom Popover issue in iOS7 and iOS8

I am developing an app for iPad only. In which in for one functionality i want to display FullCustom Popover.
For that my code is as below:-
DuplicateViewController *viewControllerForPopover =
[self.storyboard instantiateViewControllerWithIdentifier:#"DuplicatePopoverVC"];
viewControllerForPopover.arr_studentDetail = self.arrStudentDetail;
viewControllerForPopover.dictSelectedProg = dictSelectedProgram;
self.popover = [[UIPopoverController alloc]
initWithContentViewController:viewControllerForPopover];
[self.popover setPopoverContentSize:CGSizeMake(self.view.frame.size.width, self.view.frame.size.height)];
viewControllerForPopover.modalPresentationStyle = UIModalPresentationFullScreen;
[self.popover setBackgroundColor:[[UIColor darkGrayColor] colorWithAlphaComponent:0.4]];
[self.popover presentPopoverFromRect:self.view.bounds inView:self.view permittedArrowDirections:0 animated:YES];
I set popover size and tried with other option but can't make it full screen.
ViewDidLoad -> DuplicateViewController
[view_main.layer setBorderWidth:5.0f];
[view_main.layer setCornerRadius:25.0f];
[view_main.layer setBorderColor:[UIColor colorWithRed:(29.0f/255.0f) green:134.0f/255.0f blue:140.0f/255.0f alpha:1.0f].CGColor];
But while running App, It display as below:-
Please help me to display full screen Popover. Thank you so much in advance.
create two classes
the first one should inherit UIPopoverController
the second one should inherit UIPopoverBackgroundView
for example:
CustomUIPopoverController.h
#interface CustomUIPopoverController : UIPopoverController
CustomUIPopoverController.m
#implementation CustomUIPopoverController
- (id)initWithContentViewController:(UIViewController *)viewController {
self = [super initWithContentViewController:viewController];
if (self) {
self.popoverBackgroundViewClass = [CustomUIClearPopoverBackgroundView class];
[self setPopoverContentSize:viewController.view.frame.size];
}
return self;
}
#end
CustomUIClearPopoverBackgroundView.h
#interface CustomUIClearPopoverBackgroundView : UIPopoverBackgroundView
CustomUIClearPopoverBackgroundView.m
#import "CustomUIClearPopoverBackgroundView.h"
#implementation CustomUIClearPopoverBackgroundView
#pragma mark - no arrow
+ (CGFloat)arrowHeight {
return 0;
}
+ (CGFloat)arrowBase {
return 0;
}
- (CGFloat)arrowOffset {
return 0;
}
- (void)setArrowOffset:(CGFloat)arrowOffset {
}
- (UIPopoverArrowDirection)arrowDirection {
return 0;
}
- (void)setArrowDirection:(UIPopoverArrowDirection)arrowDirection {
}
#pragma mark - no margins
+ (UIEdgeInsets)contentViewInsets {
return UIEdgeInsetsZero;
}
#pragma mark - fully transparent (default is 0.15)
+(BOOL)wantsDefaultContentAppearance {
return NO;
}
- (void)willMoveToWindow:(UIWindow *)newWindow {
[super willMoveToWindow:newWindow];
// hide shadow image view
[self.superview.subviews[0] setHidden:YES];
}
#end
I used this but I don't like it very much.
the second option is to create a container view and hide/show it as you like.
this way it's a pure view controller and you don't need to mess with popup stuff
to create the transparency, make your container view background = clear, the view controller view background color = clear, and add a semi-transparent button in the size of the view controller for the semi-transparent black background. on click of the button close the window (= same effect as tapping the popup background)

iOS navigation issue: after pushing a ViewController, it results in a navigation bar showing the navigation items of the previous ViewController

This situation happens very rarely and I don't know how to reproduce it, but it does happen sometimes and I would like to fix it.
In ViewController A, if I push ViewController Bin, sometimes(not always) when ViewController B did appear, the navigation bar is showing the navigation bar items of ViewController A, not those of ViewController B. If I click on the back button, I cannot go back to ViewController A, getting stuck in ViewController B.
A UIBarButtonItem is added to the navigation items of ViewController A, and the navigation items of ViewController A will be updated in response to some events. Is it the reason that causes this issue?
Codes for pushing ViewController B
ViewControllerB* viewControllerB = [ViewControllerB new];
[self.navigationController pushViewController:viewControllerB animated:YES];
Codes for updating the navigation items in ViewController A
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
if(NumberOfCalendarOperations == 0){
[self showNavigatorBarButtons];
}
else{
[self startRefreshAnimationOnUpdateButton];
}
}
//This method is triggered through notification when the number of operations in calendarOperationQueue is changed
-(void)calendarOperationQueueStateDidChange:(NSNotification*)notification{
if(NumberOfCalendarOperations == 0){
if (self.isShowActivityIndicator) {
dispatch_async(dispatch_get_main_queue(), ^{
[self showNavigatorBarButtons];
});
}
}
else{
if (!self.isShowActivityIndicator) {
dispatch_async(dispatch_get_main_queue(), ^{
[self startRefreshAnimationOnUpdateButton];
});
}
}
}
/**
* Show the update button on the right of navigation bar
*/
-(void)showNavigatorBarButtons{
self.isShowActivityIndicator = NO;
UIBarButtonItem *updateButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"sync.png"] style:UIBarButtonItemStylePlain target:self action:#selector(updateButtonDidPress:)];
[self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:updateButton, nil]];}
/**
* Start refresh animation on the update button
*/
-(void)startRefreshAnimationOnUpdateButton{
if (self.navigationController.topViewController != self) {
return;
}
self.isShowActivityIndicator = YES;
UIView* updateButtonView = nil;
for (UIView *subViewInNavigationBar in self.navigationController.navigationBar.subviews){
NSString *subViewClassAsString = NSStringFromClass([subViewInNavigationBar class]);
if ([subViewClassAsString compare:#"UINavigationButton" /* TODO: be careful with this */
options:NSCaseInsensitiveSearch] == NSOrderedSame){
if ([subViewInNavigationBar isKindOfClass:[UIView class]] == YES){
if(updateButtonView == nil){
updateButtonView = subViewInNavigationBar;
}
else if(subViewInNavigationBar.center.x < updateButtonView.center.x){
updateButtonView = subViewInNavigationBar;
}
}
}
}
for (UIView *subViewsInButton in updateButtonView.subviews){
if ([subViewsInButton isKindOfClass:[UIImageView class]] == YES &&
subViewsInButton.frame.origin.x != 0.0f &&
subViewsInButton.frame.origin.y != 0.0f){
[subViewsInButton removeFromSuperview];
CGRect activityIndicatorFrame = self.updateButtonActivityIndicator.frame;
activityIndicatorFrame.origin.x = (CGRectGetWidth(updateButtonView.frame) / 2.0f) - (CGRectGetWidth(activityIndicatorFrame) / 2.0f);
activityIndicatorFrame.origin.y = (CGRectGetHeight(updateButtonView.frame) / 2.0f) - (CGRectGetHeight(activityIndicatorFrame) / 2.0f);
self.updateButtonActivityIndicator.frame = activityIndicatorFrame;
[self.updateButtonActivityIndicator startAnimating];
[updateButtonView addSubview:self.updateButtonActivityIndicator];
return;
}
}
}
Anyone has got a clue? Thank you.
Finally I found the reason of this issue. It is that I try to hide the navigation bar in viewWillDisappear. Now iOS allows me to back to the previous view by panning from the left edge of the screen. But while panning from the left edge, if I cancel this action, and pan back to the left edge, the navigation bar will enter this strange state.

When my application first launches, iAd refuses to load an ad on the first screen

When my application launches, iAd refuses to load an ad on the first screen. No error message, nothing. If I switch screens (going to another screen), it starts getting ads and serving them up, even when I go back to the first screen.
I am using a single iAd instance that is in the ApplicationDelegate. I am attempting to link in the iAdBanner in viewDidAppear, and unlink in viewWillDisappear.
The viewDidAppear method:
- (void)viewDidAppear:(BOOL)animated
{
NSLog(#"view did appear");
[super viewDidAppear:animated];
ADBannerView *adBanner = SharedAdBannerView;
adBanner.requiredContentSizeIdentifiers = (&ADBannerContentSizeIdentifierPortrait != nil) ?
[NSSet setWithObjects:ADBannerContentSizeIdentifierPortrait, ADBannerContentSizeIdentifierLandscape, nil] :
[NSSet setWithObjects:ADBannerContentSizeIdentifier320x50, ADBannerContentSizeIdentifier480x32, nil];
[self.view addSubview:adBanner];
// set the delegate to self, so that we are notified of ad responses
[adBanner setDelegate:self];
isAdShown = [adBanner isBannerLoaded];
[self layoutForCurrentOrientation:animated];
}
The layout method:
- (void)layoutForCurrentOrientation:(BOOL)animated
{
//TODO: this only handles bottom-located elements
ADBannerView *adBanner = SharedAdBannerView;
CGFloat animationDuration = animated ? 0.2f : 0.0f;
// by default content consumes the entire view area
CGRect contentFrame = contentView.bounds;
CGRect owningViewFrame = [self view].bounds;
// the banner still needs to be adjusted further, but this is a reasonable starting point
// the y value will need to be adjusted by the banner height to get the final position
CGPoint bannerOrigin = CGPointMake(CGRectGetMinX(owningViewFrame), CGRectGetMaxY(owningViewFrame));
CGFloat bannerHeight = 0.0f;
// First, setup the banner's content size and adjustment based on the current orientation
if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
adBanner.currentContentSizeIdentifier = (&ADBannerContentSizeIdentifierLandscape != nil) ? ADBannerContentSizeIdentifierLandscape : ADBannerContentSizeIdentifier480x32;
else
adBanner.currentContentSizeIdentifier = (&ADBannerContentSizeIdentifierPortrait != nil) ? ADBannerContentSizeIdentifierPortrait : ADBannerContentSizeIdentifier320x50;
bannerHeight = adBanner.bounds.size.height;
// Depending on if the banner has been loaded, we adjust the content frame and banner location
// to accomodate the ad being on or off screen.
// This layout is for an ad at the bottom of the view.
if (isAdShown)
{
NSLog(#"Banner is loaded");
contentFrame.size.height = owningViewFrame.size.height - bannerHeight;
bannerOrigin.y -= bannerHeight;
}
else
{
NSLog(#"Banner is not loaded");
bannerOrigin.y += bannerHeight;
contentFrame.size.height = owningViewFrame.size.height;
}
NSLog(#"Banner content Frame: (%f, %f), (%f, %f)", bannerOrigin.x, bannerOrigin.y, contentFrame.size.width, contentFrame.size.height);
// And finally animate the changes, running layout for the content view if required.
[UIView animateWithDuration:animationDuration
animations:^{
contentView.frame = contentFrame;
[contentView layoutIfNeeded];
adBanner.frame = CGRectMake(bannerOrigin.x, bannerOrigin.y, adBanner.frame.size.width, adBanner.frame.size.height);
}];
}
and the viewWillDisappear method:
-(void)viewWillDisappear:(BOOL)animated
{
NSLog(#"View will disappear");
[super viewWillDisappear:animated];
[self removeLinkToAdBanner:animated];
}
-(void)removeLinkToAdBanner:(BOOL)animated
{
ADBannerView *adBanner = SharedAdBannerView;
if ([adBanner delegate] == self) {
adBanner.delegate = nil;
[adBanner removeFromSuperview];
}
}
The real frustration was this was working in the simulator before I upgraded to xcode 4. I upgraded, and all of a sudden it has stopped working. Anyone else seen behavior like this? Any ideas what I can do to fix it? The behavior occurs in the simulator on all test versions of 4.x (4.0 through 4.3).
I have encountered the same problem, and the fix is in the AppDelegate's bannerViewDidLoadAd method. You need to call your showBanner method there in order for the ad to display initially.
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
[_currentController showBannerView:_bannerView animated:YES];
}
Please check the new iAdSuite sample codes where I took this out.
iAdSuite Sample Code Updated 10/31/11

Resources