I an using a stepper to control the font size of a text view, but there is no action being fired until I press the stepper twice. Why is this happening?
The following code is for the `mystepper' IBAction:
- (IBAction) changeFontSize:(id)sender
{
[myStepper setMinimumValue:14.0]
self.myStepper.maximumValue =20.0;
CGFloat newSize = [myTextView fontWithSize:self.stepper.value];
self.myTextView.font = newSize;
}
Check whether u had connected the UIStepper Recieved Actions to the changeFontSize: function for Values Changed not for Touches inside
Related
In a application for iPad, I'm trying to build a slider that only moves up, and it will be reseted by a button.
I found out how to put it vertically, just make a transform: CGAffineTransformMakeRotation.
But how can I block the slider to move down??
Any help will be appreciated.
Thanks.
You need to setup a handler for the slider's value:
[slider addTarget:self action:#selector(sliderUpdated:) forControlEvents:UIControlEventValueChanged];
You need an instance variable for the current slider value:
float _sliderValue;
And you need to implement the sliderUpdated: method you setup above.
- (void)sliderUpdated:(UISlider *)slider {
float val = slider.value;
if (val < _sliderValue) {
// The user tried to move the slider down - move it back up
slider.value = _sliderValue;
} else {
// The user moved the slider up - save this as the new value
_sliderValue = val;
}
}
Make sure that your "Reset" button handler resets the _sliderValue back to the slider's minimum value.
You could make a custom UISlider subclass and implement the - (BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event method to check if the slider is being moved down.
I am developing an iPhone app which has a shopping cart, and I'm using a UITableView to display the cart. There is a cell for each item, and the -tableFooterView is set to a custom view which gives the user a text field to verify their credit card's CVV and a button to complete the checkout process.
When the user taps in the CVV text field, I resize the table view so that the keyboard doesn't cover anything.
- (void)keyboardWillShow:(NSNotification *)n
{
// I'll update this to animate and scroll the view once everything works
self.theTableView.frameHeight = self.view.frameHeight - KEYBOARD_HEIGHT_PORTRAIT_IPHONE;
}
After entering their CVV, the user can tap the Done key to dismiss the keyboard:
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return NO;
}
All of that works, however, while the keyboard is visible, my checkout button (a normal UIButton) does not respond to touch events. The table scrolls, but the button's touchUpInside event is never fired.
Once I tap Done and the keyboard is dismissed, the checkout button will recognize touchUpInside events.
From what I've seen, it appears that any button that was covered by the keyboard does not respond to my touches (even it scrolled out from behind the keyboard) until the keyboard is dismissed. Buttons in this same -tableFooterView that are not ever covered by the keyboard remain responsive to touch while the keyboard is visible.
Same behavior when running on iOS 5 and iOS 4.
Can anyone offer any suggestions of what may be going on? Or any helpful ideas for troubleshooting?
Thanks!
Edit - Update
In fact, the portion of the tableFooterView that is covered by the keyboard is not responding to touch events. In my custom UIView subclass, I implemented -touchesBegan:withEvent: and just log that a touch occurred.
Touching anywhere in the view gets a log statement before the keyboard is shown. However, after the tableview is resized, only touching the upper portion of the view generates a log statement.
Also I just realized, the portion of the tableFooterView that was covered by the keyboard turns to the color of the containing view's background color once I scroll that portion to be visible.
I had the same problem. I think it is a bug in iOS, but I've discovered a workaround for it:
- (void)keyboardWillShow:(NSNotification *)note {
NSDictionary* userInfo = [note userInfo];
// get the size of the keyboard
NSValue *boundsValue = [userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey];
CGSize keyboardSize = [boundsValue CGRectValue].size; // screen size
CGFloat keyboardHeight;
if (self.interfaceOrientation == UIInterfaceOrientationPortrait ||
self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
keyboardHeight = keyboardSize.height;
} else {
keyboardHeight = keyboardSize.width;
}
// resize the view with the keyboard
__block CGRect origFrame = self.view.frame;
__block CGRect viewFrame = origFrame;
viewFrame.size.height -= keyboardHeight - ((self.tabBarController != nil) ? self.tabBarController.tabBar.frame.size.height : 0);
// Set the height to zero solves the footer view touch events disabled bug
self.view.frame = CGRectMake(origFrame.origin.x, origFrame.origin.y,
viewFrame.size.width, 0);
// We immediately set the height back in the next cycle, before the animation starts
dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
self.view.frame = origFrame; // The original height
// start the animation
[UIView animateWithDuration:0.4 animations:^{
[self.view setFrame:viewFrame];
}];
});
}
The trick is to set the height of the tableView to 0 and back to original in the next running cycle.
This works for me either iOS 4.3 and 5.1.
I think that resizing the UITableView causes it to send the UIButton (a subview) to the back of the view hierarchy. You may need to bring it to the front explicitly after resizing the frame.
[self.theTableView bringSubviewToFront:yourUIButton];
Following worked for me.
Had a table view footer with button, for that button action is linked via xib, apart from that added following code more -
#IBOutlet private weak var myButton: CustomUIButton!
override public func awakeFromNib() {
super.awakeFromNib()
let myButtonTapGesture = UITapGestureRecognizer(target: self, action: #selector(myButtonAction(_:)))
myButton.addGestureRecognizer(myButtonTapGesture)
}
#IBAction func myButtonAction(_ sender: AnyObject) {
// button action implementation
}
So I have to add a tap gesture on button.
i have IBOutlet uislider. i want it to show the value of slider when the user presses the slider and change the value of it when the user take his hand off the slider i want it to disapper. So when the user touches to change the value of slider the label shows the value and when the user take his finger of the slider the label automaticly disapper.
My code is:
-(IBAction)sliderSlide:(UISlider *)aSlider {
float f=slider.value;
NSString *show=[NSString stringWithFormat:#"%.2f %%",f];
label2.text=show;
}
i know i need to use slider.highlited=YES; but where and how can i turn it back to hidden?
- (IBAction)touchEndedAction
{
self.label2.hidden = YES;
}
set the IBAction to the sliders UIControlEventEditingDidEnd or UIControlEventTouchCancel
try it out.
UIControlEventEditingDidEnd didn't work for me, but UIControlEventTouchDown works
I want to have a text-send view like the send-email view from the email app by apple. (the default iPhone emailapp).
I tried a UIScrollView with 2 TextFields and 1 TextView, but it looks not good, the scrollview has no function and the view does not scroll when I enter a text in the TextView (the text is hiding in the third line when I type...
Here is a picture:
http://s3.imgimg.de/uploads/Bildschirmfoto20110823um1156940f792556940f791456940f79png.png
It should look like this:
http://a5.mzstatic.com/us/r1000/032/Purple/ea/4f/03/mzl.bxracfen.320x480-75.jpg
How to rebuild?
to scroll downside when you start writing the text inside UITextfield, use this :
[yourScrollView scrollRectToVisible:CGRectMake(yourTextfield.frame.origin.x,yourTextField.frame.origin.y,yourScrollView.frame.size.width,yourScrollView.frame.size.height) animated:YES];
Also, when you edit your TextView (i.e in the textViewDidBeginEditing method), make its frame smaller so as to make it fully visible. Then, when you finish editing the text (i.e in the textViewDidEndEditing method) set the frame to whatever it was, originally.
EDIT:
//add this in .h file
NSInteger originalHeight;
//in .m file
- (void) textViewDidBeginEditing:(UITextView *)textView
{
[yourScrollView scrollRectToVisible:CGRectMake(yourTextView.frame.origin.x,yourTextView.frame.origin.y,yourScrollView.frame.size.width,yourScrollView.frame.size.height) animated:YES];
//now set the frame
//you just need to change the height, rest can be kept whatever they are
//set the newHeight so as to make the textview visible
originalHeight = yourTextView.frame.size.height;
yourTextView.frame = CGRectMake(x,y,width,newHeight);
//rest of the code
}
Now when editing is completed, set the height to as it was before.
- (void) textViewDidEndEditing:(UITextView *)textView
{
yourTextView.frame = CGRectMake(x,y,width,originalHeight);
}
In my iPhone app I'm using a slider for adjusting the volume and working fine.
But I'm not able to set a default value for slider when app loads.
I have seen that only when the slider is touched the value gets changed.But i need a default value when app loads.
My code is given below
- (IBAction)sliderChanged:(id)sender {
slider = (UISlider *) sender;
slider.minimumValue = 0.5;
slider.maximumValue = 2.2;
progressAsInt = slider.value ;
}
how can i solve this issue.
please help.Thanks in advance.
There are two ways to change default value of slider.
Using Interface builder. See attached picture and value of current property.
Using Code
You just need to write this one line in viewWillAppear delegate method.
-(void)viewWillAppear:(BOOL)animated{
slider.value = 1.0;
}
Hope this help.
First you'll need to set the slider to an IBOutlet iVar of the view controller where the slider is.
Then, in the viewDidLoad of that view controller, you can set the value you want.
(Also, you should be able to do it in Interface Builder, but I'm not very familiar with it).