iOS: Custom button not showing on Storyboard - ios

I am displaying an image programatically in my storyboard and handling successfully landscape/portrait orientation (see code below). I'm trying now to add a custom button on that same view in the storyboard via Interface Builder directly. The button just does not show up when the app runs. Only the image. Could you show me the way to do it on the storyboard view? Or should I add it programatically as well? Or redo everything 100% in Interface builder? Don't really know how to mix and match these 2 methods...
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[[self navigationController] setNavigationBarHidden:YES animated:YES];
UIImage *startImage = [UIImage imageNamed:#"title.png"];
UIImageView *startImageView = [[UIImageView alloc] initWithImage:startImage];
self.startImageView = startImageView;
[self.view addSubview:startImageView];
}
- (void) orientStartImageView
{
UIInterfaceOrientation curOrientation = [UIApplication sharedApplication].statusBarOrientation;
if (curOrientation == UIInterfaceOrientationPortrait || curOrientation == UIInterfaceOrientationPortraitUpsideDown) {
[self.startImageView setFrame:CGRectMake(-128, 0, 1024, 1024)];
}else{
[self.startImageView setFrame:CGRectMake(0, -128, 1024, 1024)];
}
}
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self orientStartImageView];
}
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
[self orientStartImageView];
}

Its bcoz you are adding ImageView on top of the Button, you can bring it to front using this code, put it in viewdidload method :
[self.view bringSubviewToFront:yourBtn];

Related

Reload/Refresh View Controller with a specific subview

i have a UIViewController with several specific subviews (like PassBook Views).
When i exit a view i want to reload the ViewController and all his subviews. i call the viewDidLoad and viewWillLayoutSubviews method of the rootviewController like this:
- (IBAction)disconnect:(UIStoryboardSegue *)segue {
self.sourceVC = segue.sourceViewController;
self.disconnected = YES;
ViewController *rootController=(ViewController *)((AppDelegate *)[[UIApplication sharedApplication] delegate]).window.rootViewController;
[rootController viewDidLoad];
[rootController viewWillLayoutSubviews];}
in my ViewController class:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[self setupPBDataSource];}
- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
CGRect frame = self.view.bounds;
CGFloat maxY = (([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)\
? 20 : 0);
frame.origin.y += maxY;
frame.size.height -= maxY;
if (!_passbookView) {
self.passbookView =
[[PBPassGroupStackView alloc] initWithFrame:frame datasource:self];
[self.view addSubview:self.passbookView];
} else {
[self.passbookView removeFromSuperview];
self.passbookView =
[[PBPassGroupStackView alloc] initWithFrame:frame datasource:self];
[self.view addSubview:_passbookView];
}}
i just want to know how to reload my new passbookView (with two new subviews created on a login segue) ??? thanks.

How to disable darker transparent effect in UIPopoverController in iOS7?

I use UIPopoverController to popup an view in iPad iOS7 like this:
if (!self.popover) {
UIViewController *popupVC = [[UIViewController alloc] init];
[popupVC.view addSubview:thePopupView];
popupVC.preferredContentSize = CGSizeMake(240, 140);
self.popover = [[UIPopoverController alloc] initWithContentViewController:popupVC];
self.popover.delegate = self;
}
[self.popover presentPopoverFromBarButtonItem:barButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
But when popover active, it make screen darker while this effect not affect other views in iOS6.
How to overcome this issue? Thanks!
If you mean the dimming view that is inserted under the popover, there is only one workaround - use a custom popoverBackgroundViewClass.
It's complicated, but not as complicated as you might think.
Another method is to traverse the popover view stack and remove the dimming view manually, as shown here in a UIPopoverController subclass:
#property (nonatomic, assign) BOOL showsDimmingView;
....
- (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item
permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections
animated:(BOOL)animated
{
[super presentPopoverFromBarButtonItem:item
permittedArrowDirections:arrowDirections
animated:animated];
if (!_showsDimmingView) {
[self removeDimmingView:[[UIApplication sharedApplication].keyWindow.subviews lastObject]];
}
}
- (void)presentPopoverFromRect:(CGRect)rect
inView:(UIView *)view
permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections
animated:(BOOL)animated
{
[super presentPopoverFromRect:rect
inView:view
permittedArrowDirections:arrowDirections
animated:animated];
if (!_showsDimmingView) {
[self removeDimmingView:[[UIApplication sharedApplication].keyWindow.subviews lastObject]];
}
}
- (void)removeDimmingView:(UIView *)subview
{
for (UIView *sv in subview.subviews) {
if (sv.alpha == 0.15f && [sv isKindOfClass:NSClassFromString(#"_UIPopoverViewBackgroundComponentView")]) {
sv.alpha = 0.f;
}
const CGFloat *components = CGColorGetComponents(sv.backgroundColor.CGColor);
if (sv.backgroundColor && (components[1] == 0.15f || sv.alpha == 0.15f)) {
[sv removeFromSuperview];
}
[self removeDimmingView:sv];
}
}

How to default the root view controller to landscape with a size of 1024x768

I'm developing an iPad app that needs to be restricted to landscape mode. I've got a root view controller
and a subview controller. I add the sub view controller to the root view controller and set their
frames to 1024x768. I restricted the app to landscape mode in info.plist and in my view controllers'
shouldAutorotateToInterfaceOrientation:interfaceOrientation method. However, the dimensions for
the subview get reset to 768x1024 sometime before the viewDidAppear method which makes it appear
as if it's in portrait mode.
The strange part is if I set the frame for the subview so that the width or height are something
other than the screen dimensions, for example: CGRectMake(0, 0, 1024, 767) or CGRectMake(0, 0, 1024, 769), it doesn't get reset and
displays in what looks like landscape mode.
So my question is, what's causing this behavior. And what's the best way to simply default all views
to landscape mode
Here's my root view controller:
// INTERFACE
#import <UIKit/UIKit.h>
#import "ScrapViewController.h"
#interface ViewController : UIViewController
{
ScrapViewController *svc;
}
#end
// IMPLEMENTATION
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor blueColor];
self.view.frame = CGRectMake(0, 0, 1024, 768);
svc = [[SubViewController alloc] init];
svc.view.backgroundColor = [UIColor redColor];
svc.view.frame = CGRectMake(0, 0, 1024, 768);
[self.view addSubview:svc.view];
NSLog(#"viewDidLoad rvc %f,%f", self.view.frame.size.width, self.view.frame.size.height);
NSLog(#"viewDidLoad svc %f,%f", svc.view.frame.size.width, svc.view.frame.size.height);
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight;
}
#end
Here's my sub view controller
// INTERFACE
#import <UIKit/UIKit.h>
#interface SubViewController : UIViewController
#end
// IMPLEMENTATION
#implementation SubViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight;
}
#end
if you uses xib files then just make your subview's xib to represent it as landscape by default ie the default design of nib file will be landscap ie make your subview's view landscap in property window

Very odd iOS orientation issue with Three20

This is amongst the oddest issues with iOS development I have ever seen. I'm relatively new to iOS development, so I apologize if I'm missing something obvious or my terminology isn't completely correct. If you need clarification, please let me know in the comments and I'll edit my question accordingly.
The Problem
I'm using Three20, so that might have something to do with it. But I have a "Home view" which is basically a series of images that link out to other views (shown in the image below). If I start our in portrait view, all is well.
The next view is a table view, shown below:
YAY! I can rotate and all is right with the world. BUT if I go back to that home view, rotate to landscape, and THEN go to this tabled view, the world breaks.
You'll see that there's a random space added to the right side of my table now. I don't know where and how it came from. Here's my Controller.m file:
#import "FriendTabsController.h"
#import "MyAppApp.h"
#import "JohnDoeManager.h"
#implementation FriendTabsController
#synthesize innerView, segmentedControl, innerController, friendsController, friendRequestsController;
- (void)addBottomGutter:(UIViewController*)controller {
if ([controller isKindOfClass:[TTTableViewController class]]) {
TTTableViewController* tableViewController = (TTTableViewController*)controller;
tableViewController.tableView.scrollIndicatorInsets = UIEdgeInsetsMake(0,0,50+44,0);
tableViewController.tableView.contentInset = UIEdgeInsetsMake(0,0,50+44,0);
}
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
self.title = #"Friends";
self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
self.navigationController.navigationBar.tintColor = nil;
friendsController = [[FriendsController alloc] init];
friendRequestsController = [[FriendsController alloc] init];
((FriendsController*)friendRequestsController).friendRequests = YES;
[self addBottomGutter:friendsController];
[self addBottomGutter:friendRequestsController];
innerController = friendsController;
[innerView addSubview:innerController.view];
[innerController viewDidLoad];
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
[self loadBannerAd:(orientation)];
}
-(void) loadBannerAd:(UIInterfaceOrientation)orientation{
MainLayer *mi = [MainLayer getInstance];
if (mi.useJohnDoeAds) {
[[JohnDoeManager sharedInstance] setCurrentViewController:self];
[mi.JohnDoeBanner.view removeFromSuperview];
if(orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
// This is a portait ad
if ([[MyAppUtils getCurrentDevice] isEqualToString:#"iphone"]) {
[mi.JohnDoeBanner setFrame:CGRectMake(0, 410-44, 320, 50)];
}else{
[mi.JohnDoeBanner setFrame:CGRectMake(0, 1024-44-90-20, 768, 90)];
}
} else {
// Landscape
if ([[MyAppUtils getCurrentDevice] isEqualToString:#"iphone"]) {
[mi.JohnDoeBanner setFrame:CGRectMake(0, 320-44-58, 410, 50)];
}else{
[mi.JohnDoeBanner setFrame:CGRectMake((1024-768)/2, 768-44-90-20, 768, 90)];
}
}
[self.view addSubview:mi.JohnDoeBanner.view];
[mi.JohnDoeBanner rollOver];
}
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self loadBannerAd:(toInterfaceOrientation)];
}
- (IBAction)didChangeSegment:(UISegmentedControl *)control {
if (innerController) {
[innerController viewWillDisappear:NO];
[innerController.view removeFromSuperview];
[innerController viewDidDisappear:NO];
}
switch (control.selectedSegmentIndex) {
case 0:
innerController = friendsController;
self.title = #"Friends";
break;
case 1:
innerController = friendRequestsController;
self.title = #"Requests";
break;
}
[innerController viewWillAppear:NO];
[innerView addSubview:innerController.view];
[innerController viewDidAppear:NO];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[innerController viewWillAppear:animated];
self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
self.navigationController.navigationBar.tintColor = nil;
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[innerController viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated {
[innerController viewWillDisappear:animated];
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated {
[innerController viewDidDisappear:animated];
[super viewDidDisappear:animated];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
[friendsController release], friendsController = nil;
[friendRequestsController release], friendRequestsController = nil;
[super viewDidUnload];
}
- (void)dealloc {
[super dealloc];
}
#end
So can someone please tell me what's going on? HELP!
You need to set wantsFullScreenLayout property to YES.
in your init methods set
self.wantsFullScreenLayout = YES;
This will solve your problem.

Providing autorotation support to a subview loaded programmatically - iPad

I have an iPad project structured as:
- AppDelegate
- MainWindow
- View Controller
-- View
The View Controllers .m file loads another view programmatically and positions it on the screen. This view is going to be slid in and out.
I do this:
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect viewRect = CGRectMake(0, 0, 0, 0);
CalculatorView *v = [[[CalculatorView alloc]
initWithFrame:viewRect] autorelease];
[self.view.window addSubview:v];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
v.view.frame = CGRectMake(0, 0, 460, 320);
[UIView commitAnimations];
}
The issue that I am having is that the subview I'm adding here doesnt' seem to have the correct orientation. The project supports ONLY landscape, and launches to landscape. The container view is fine, and it contains some buttons which are fine as well. However this programmatically loaded view is stuck in Portrait mode. I have provided the following auto-rotation code (In the loaded view's .m):
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
But it never gets called.
So, how can I get the programmatically added subview to load in landscape and NOT portrait mode?
TIA!
The UIView class does not receive orientation change messages.
(specially the shouldAutorotateToInterfaceOrientation method, which is a UIViewController Method)
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006926-CH3-SW23
You will have to manually add a method in your view to inform it that the orientation has changed and you should call this method in your controller shouldAutorotateToInterfaceOrientation method.
To do that you will have to create a reference to you view in your controller and take care of the memory yourself.
#interface MyController : UIViewController {
CalculatorView *_calculatorView;
}
#end
#implementation MyController
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect viewRect = CGRectMake(0, 0, 0, 0);
//inits _calculatorView without the autorelease. Will be released in the dealloc method
_calculatorView = [[CalculatorView alloc]
initWithFrame:viewRect];
[self.view.window addSubview:v];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
_calculatorView.view.frame = CGRectMake(0, 0, 460, 320);
[UIView commitAnimations];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
//calls custom interface orientation method
[_calculatorView MyInterfaceChangedCustomMethod:interfaceOrientation];
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
-(void) dealloc {
[_calculatorView release];
[super dealloc];
}
#end
EDIT: If you CalculatorView is simple and all you need is to change its frame properly after the device rotation, I think the best approach would be using you view's autoresizingMask similar to the following
_calculatorView = [[CalculatorView alloc]
initWithFrame:viewRect];
_calculatorView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

Resources