Disable UIView and controls - iphone

When a user clicks on a button a popup similar to this image appears. But when i am on a slow internet, the popup takes awhile to load. so until the popup loads i need the view in the background (where the button resides) to freeze (disable) and the user should not be able to click on any controls.
How can i disable the view/control ?

See -[UIView userInteractionEnabled]
http://developer.apple.com/library/ios/documentation/uikit/reference/uiview_class/uiview/uiview.html#//apple_ref/occ/instp/UIView/userInteractionEnabled
Set
view.userInteractionEnabled = NO;
On the parent view of the controls you'd like disabled.

Set the button's enabled property to NO - if you're using UIButton or a subclass thereof.
ex.
[button setEnabled:NO];

UIView *testView = [[UIView alloc] init];
testView.userInteractionEnabled = NO;

Related

UIView not appearing over keyboard?

I have this code:
JMenuController *menuController = [[JMenuController alloc] init];
NSArray *buttonsArray = [NSArray arrayWithObjects:#"From Libary", #"Take Photo or Video", nil];
[menuController showMenuWithTitle:#"Add Media" ButtonTitles:buttonsArray animated:YES];
self.currentMenuType = JCreateMenuTypeNewMedia;
[[[[UIApplication sharedApplication] delegate] window] addSubview:menuController];
The problem is, the view appears below the keyboard, which is already on screen. How do i fix this?
The easiest way to display some view on top of the keyboard is put that view inside a UIWindow for which you set the windowLevel property to UIWindowLevelAlert. Something like:
UIView *myView = [[UIView alloc] initWithFrame:rect];
UIWindow *myWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
myWindow.windowLevel = UIWindowLevelAlert;
[myWindow addSubview:myView];
[myWindow makeKeyAndVisible];
If you're using ARC, make sure you keep a strong reference to myWindow. Otherwise, it'll get automatically released and so it won't get added to your application windows.
(This is how UIActionSheet and UIAlertView work internally. When one of them is visible, have a look at [UIApplication sharedApplication].windows and you'll see they create windows with their windowLevel set to UIWindowLevelAlert.)
Ok it took awhile for me to understand what you wanted to do. You have 2 options.
Resign the keyboard and show the view with the buttons.
Use a UIActionSheet to display the buttons over the keyboard like it does in the Messages application when you press the camera to send a picture to someone.
I would recommend the later.
Edit:
Take a look at this for your custom UIActionSheet Show a view over the keyboard
The keyboard exists in its own window. To put things over it, you either have to put things into the keyboard's window (this is not a supported behavior), or create yet another window and put it over the keyboard.

How do I launch a modal view from a custom UITabBar?

I've built out the raised-center UITabBar from this GitHub location.
My challenge now is that I can't figure out how to create a modal view that will appear when the button is pressed.
Has anyone used the idev-recipes RaisedCenterTabBar with luck? How did you implement the modal sheet that appears there?
Alternatively, is there a different gitHub project that has a working custom tab bar with a modal sheet?
Thank you!
Here was my solution, it was BY FAR the cleanest way I found to do this... I really hope it helps, I spent hours researching the best ways.
I setup a "UITabBarController" delegate that connects directly to my tab interface built out on my storyboard.
** Don't forget to include the "tabBarController" delegate in your header file
** Notice this callback method is NOT the "didSelectViewController" but rather the "shouldSelectViewController". This method handles the request before the tab is selected and that is exactly what you want so you can STOP the request before it ever happens... This way you don't have to save the current index you are on, pass it around and all that nonsense.
Then I am simply checking what tab WILL be selected (based on the view controller's title.
** Also: this is my code, change it as needed for your code. But the principals should remain. My "performSegueWithIdentifier" is actually a manual segue connected to my tab controller that opens in a modal. This code is working brilliant for me.
-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
if([[viewController title] isEqualToString:#"tellvc"])
{
[self performSegueWithIdentifier:#"shareModelViewController" sender:Nil];
return NO;
}
else
{
return YES;
}
}
I have something similar in a program of mine that I'm working on and would be glad to show you how I do it. I have a couple of viewControllers in a TabBar. I create my Plus button in whichever VC I decide will appear first on the screen in ViewDidLoad.
// Create a plus button that appears on the tabBar
UIImage *plusButton = [UIImage imageNamed:#"plusbutton.png"];
UIView *tabBarView = [[self tabBarController] view];
addButton = [UIButton buttonWithType:UIButtonTypeCustom];
[addButton setFrame:CGRectMake(127.0, 432.0, [plusButton size].width, [plusButton size].height)];
[addButton setBackgroundImage:plusButton forState:UIControlStateNormal];
[tabBarView addSubview:addButton];
[addButton addTarget:self action:#selector(scalePicker:) forControlEvents:UIControlEventTouchUpInside];
I make the button a subView of the tabBarController's view. Later on in the implementation of this VC I have a method called scalePicker: which creates and instance of one of my other VC's and presents it modally. Here is the code for that: (note: this is the method that I set as a target for the plus button in the code above)
-(void) scalePicker:(id)sender
{
// create the view scalePicker, set it's title and place it on the top of the view hierarchy
sp = [[ScalePickerVC alloc] init];
[self presentModalViewController:pickerNavController animated:YES];
}
I hope this helps you,
Good Luck!

Tap and hold: a pain in the uiBUTTon

Excuse the bad pun, I'm creating a custom tab bar in my iPhone app using UIButtons. Everything works beautifully except that when I tap and hold a button, it doesn't select it until I release it. It's really bugging me, because a standard UITabBarItem is selected on touch down and it just feels wrong.
I've set the IBAction to "Touch Down" and my code is pretty simple. Am I doing something wrong?
-(IBAction)tab1Pressed:(id)sender
{
if (self.tab1.selected == NO) {
self.tab1.selected = YES;
self.tab2.selected = NO;
}
}
Got a solution! Added a UILongPressGestureRecognizer to each UIButton, instead of using IBActions. Worked like a charm!
In viewDidLoad:
tapAndHold = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector(handleTapAndHold)];
[tapAndHold setMinimumPressDuration:0.01];
[self.myTabBarButton addGestureRecognizer:tapAndHold];
[tapAndHold release];
You should use another event for your button. The default one is "touch up inside". The action is triggered when you release the button.
Using "touch down" should do what you want.
You can try subclassing a UIView and implementing touchesBegan:withEvent: method.

iOS Safari refresh button. Can I use it?

I have some text field and I need refresh button like in Safari navigation bar.
How can I use it instead of making my own?
The refresh graphic itself can be extracted using UIKit Artwork Extractor. (Or, get a refresh icon from one of the many free iphone icon sets, like Glyphish)
To place it in a UITextField like in Safari, set the UITextField rightView property to a UIImageView or UIButton with the image set to the refresh image.
UITextField* myTextField = [[[UITextField alloc] initWithFrame: CGRectMake(0,0,200,44)] autorelease];
myTextField.rightView = [[[UIImageView alloc] initWithImage: [UIImage imageNamed: #"UIButtonBarRefresh.png"]] autorelease];
You'll want to use a UIButton instead of a UIImageView if you want to get the TouchUpInside notification for the refresh button.
It's a custom safari widget. You have to make your own.

How to add a HUD? (iOS)

I am trying to have some controls appear when you push a button and have it disappear when you press a different button. Right now the HUD is comprised of an image view, and some custom buttons in a UIView called "credits". I've managed to have it disappear using:
[credits removeFromSuperview];
How do I have it reappear?
If it's just a UIImageView, you should...
[self.view addSubview:credits];
... assuming you've not released it already. On a side note, there is a really good HUD for iOS here: http://github.com/matej/MBProgressHUD
I believe you can just set the view to be hidden
[self.view setHidden:YES];
While it's hidden, you can also update the view and then show again
[self.view setHidden:NO];
You'd better set their hidden property to whether YES or NO
This method will toggle the UIView credits hidden property
- (void) toggleCredits {
[credits setHidden:![credits isHidden]];
}