I am facing a weird issue.
I have three UITextField and when keyboard overlaps the screen i am moving up the screen using code:
- (void)textFieldDidBeginEditing:(UITextField *)textField {
if(self.view.frame.size.height==568 && textField==txtVerifyPassword)
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
self.view.center = CGPointMake(originalCenter.x,originalCenter.y-100);
}
else if(self.view.frame.size.height==568 && textField==txtPassword)
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
self.view.center = CGPointMake(originalCenter.x,originalCenter.y-20);
}
}
and I am moving to original position using:
- (void)textFieldDidEndEditing:(UITextField *)textField{
self.view.center = CGPointMake(originalCenter.x,originalCenter.y);
}
Original Center in DidLoad:
- (void)viewDidLoad {
[super viewDidLoad];
originalCenter = self.view.center;
// Do any additional setup after loading the view.
}
I am adding navigation Bar Programmatically like this:
[self.navigationController setNavigationBarHidden:NO];
self.navigationItem.title = #"Demo";
UIColor *bg = [UIColor colorWithRed:9/255.0f green:161/255.0f blue:12/255.0f alpha:1.0f];
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
// iOS 6.1 or earlier
self.navigationController.navigationBar.tintColor = bg;
self.navigationController.navigationBar.titleTextAttributes = #{NSForegroundColorAttributeName: [UIColor whiteColor]};
} else {
// iOS 7.0 or later
self.navigationController.navigationBar.barTintColor = bg;
self.navigationController.navigationBar.translucent = NO;
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
self.navigationController.navigationBar.titleTextAttributes = #{NSForegroundColorAttributeName: [UIColor whiteColor]};
}
When I remove navigation the every thing works great.
But when i add it i am getting two issues:
Extra Black Space at bottom ( View doesn't go back to its original Position)
When I swipe up or down navigation bar hides (don't know why this happens)
Just use TPKeyboardAvoidingScrollView and you are good to go. Its easy and simple to use. you can easily achieve what you are trying to achieve here.
Usage :
For use withUITableViewController classes, drop TPKeyboardAvoidingTableView.m and TPKeyboardAvoidingTableView.h into your project, and make yourUITableView aTPKeyboardAvoidingTableView in the xib.
If you're not using a xib with your controller, i know of no easy way to make itsUITableView a custom class: The path of least resistance is to create a xib for it.
For non-UITableViewControllers, drop theTPKeyboardAvoidingScrollView.m andTPKeyboardAvoidingScrollView.h source files into your project, pop aUIScrollView into your view controller's xib, set the scroll view's class toTPKeyboardAvoidingScrollView, and put all your controls within that scroll view.
You can also create it programmatically, without using a xib - just use theTPKeyboardAvoidingScrollView as your top-level view.
Related
In my application I want to disable screen shots function for IOS in React-native.
Please suggest me any working package or any native code which can disable screen shots in IOS.
this is one of the solutions by the library react native prevent screenshot:, check out the link rn-screenshot
Overlay screen by added 2 two into appDelegate.m
- (void)applicationWillResignActive:(UIApplication *)application {
// fill screen with our own colour
UIView *colourView = [[UIView alloc]initWithFrame:self.window.frame];
colourView.backgroundColor = [UIColor whiteColor];
colourView.tag = 1234;
colourView.alpha = 0;
[self.window addSubview:colourView];
[self.window bringSubviewToFront:colourView];
// fade in the view
[UIView animateWithDuration:0.5 animations:^{
colourView.alpha = 1;
}];
}
- (void)applicationDidBecomeActive:(UIApplication \*)application {
// grab a reference to our coloured view
UIView \*colourView = [self.window viewWithTag:1234];
// fade away colour view from main view
[UIView animateWithDuration:0.5 animations:^{
colourView.alpha = 0;
} completion:^(BOOL finished) {
// remove when finished fading
[colourView removeFromSuperview];
}];
}
I want to show ContainerView's view controller as like this
I use the following Code and it shows as i want
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: 0.8];
if (_addLinkQuestionView.isHidden == YES)
{
_addLinkQuestionView.hidden = NO;
_addLinkQuestionView.alpha = 1.0;
}
else
{
_addLinkQuestionView.alpha = 0.0;
_addLinkQuestionView.hidden = YES;
}
[UIView commitAnimations];
but Upon a click on blurr area, i want to hide container view. that area is the UIButton. I use the following code, but it does nothing.
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: 0.8];
_addLinkQuestionView.alpha = 0.0;
_addLinkQuestionView.hidden = YES;
[UIView commitAnimations];
Any Help. Thanx in advance.
Essentially it seems you need to show a alertview behaviour where all the ui from app is disabled while only the content in the dialog is enabled.
Add a public method like showOverlayView:(UIView*)v to your app delegate
On this method create a view, set alpha and add it to keywindow.
Now add the passed view to keywindow and calculate and set
its center property.
Alternatively you could use a library like MJPopupViewController or SLPopupViewController to do the job for you.
The correct way to do this :
1- New File -> UIView -> rename it to addLinkQuestionView
2- New File -> obj c class -> rename it to addLinkQuestionView
Now u have a xib,a .h and a .m
3- Go to the xib and in file's owner select your addLinkQuestionView u created in step 2
4- Design the xib as the picture link you posted and link up appropriate outlets to addLinkQuestionView.h
5- For initialization of your uiview in .h do this :
#import "addLinkQuestionView.h"
#implementation addLinkQuestionView
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
// Initialization code.
[[NSBundle mainBundle] loadNibNamed:#"addLinkQuestionView" owner:self options:nil];
self.vuComplete.frame = CGRectMake(self.vuComplete.frame.origin.x, self.vuComplete.frame.origin.y, self.frame.size.width, self.frame.size.height);
[self addSubview:self.vuComplete];
self.vuContainer.layer.cornerRadius = 5.0;
self.vuContainer.layer.borderWidth = 1.0/[UIScreen mainScreen].scale;
self.vuContainer.layer.borderColor = [[UIColor clearColor]CGColor];
self.vuContainer.alpha = 0.0;
[self layoutIfNeeded];
}
return self;
}
-(void)awakeFromNib
{
}
- (IBAction)onBackgroundTapDismissView:(id)sender {
[UIView animateWithDuration:0.5
animations:^{self.vuContainer.alpha = 0.0;}
completion:^(BOOL finished){ }];
[self removeFromSuperview];
}
Note : - (IBAction)onBackgroundTapDismissView can be a accomplished by dropping a uitapgesturerecognizer on your addLinkQuestionView's greyed background uiview so that tapping it can dismiss the entire uiview (vuComplete)
6- Then add this in your main view controller that is presenting this pop up like this :
A- import addLinkQuestionView.h first
B- add this code on your button action that you're clicking for presenting addLinkQuestionView:
addLinkQuestionView *popup = [[addLinkQuestionView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[UIView animateWithDuration:0.25
animations:^{popup. addLinkQuestionView.alpha = 1.0;}
completion:^(BOOL finished){ }];
[self.view addSubview:popup];
Have fun!
I am trying to apply mask to backend view but am unable reach my expectation. I want the view should be like showing in the below image.
I tried to implement in my own way but the mask view also comes up from bottom. When we click on iCloud option in iPad immediately the backend view becomes in gray color and the custom view comes up from bottom. I want same feature needs to be implemented in my application. Please help me. Thanks in advance.
I strongly suggest you use this nice and tidy git code
https://github.com/jmascia/KLCPopup
KLCPopup really does a very nice job in implementing modal views with animations, blur, fade, etc.
Very easy to set up and use, it's litreally just
" choose your view "
" choose where you want it "
" Add effects if you want some "
"there you go "
have fun ;)
Follow below steps to achieve your requirements-
1) Create a BaseView & Add a CustomView on the center of the BaseView.
2) Set the background color of BaseView as black with 50% opacity.
3) Keep the actual transform of the CustomView in a variable as
CGAffineTransform m_actualTransformOfCustomView =
m_customView.transform;
4) Scale the CustomView to a small 0.01 , 0.01 using
self.m_customView.transform = CGAffineTransformScale(m_actualTransformOfCustomView, 0.01, 0.01);
4) Use [UIView amimateWithDuration:] api to change the transform of the custom view to original as-
[UIView animateWithDuration:0.5f
delay:0
options:UIViewAnimationOptionCurveEaseOut
animations:^
{
self.m_customView.transform = CGAffineTransformScale(m_actualTransformOfCustomView, 1.0, 1.0);
}
completion:^(BOOL finished)
{
}
];
}
My own way is working now properly. Here is the code snippet. Enjoy!
-(IBAction)show:(id)sender{
customView = [[UIView alloc] initWithFrame:self.view.frame]; // Mask View
customView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3f];
[self.view addSubview:customView];
// customConfigurationView // PopUp view
CGRect frameCustmVw = customConfigurationView.frame;
frameCustmVw.origin.y = self.view.frame.size.height;
frameCustmVw.origin.x = 134;
customConfigurationView.frame = frameCustmVw;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
frameCustmVw.origin.y = 200;
customConfigurationView.frame = frameCustmVw;
[self.view addSubview:customConfigurationView];
[UIView commitAnimations];
[txtClientID becomeFirstResponder];
}
-(IBAction)remove:(id)sender{
[customView removeFromSuperview]; // Remove mask view
CGRect CustmFrame = customConfigurationView.frame;
CustmFrame.origin.y = 200;//self.view.frame.size.height - customConfigurationView.frame.size.height;
customConfigurationView.frame = CustmFrame;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
CustmFrame.origin.y = self.view.frame.size.height;
customConfigurationView.frame = CustmFrame;
[UIView commitAnimations];
}
oky , my answer regarding the way how settings app doing this, it is simple ... they are just presenting a navigation controller thats all, for example
just create a view controller subclass for example (i named it as TestViewController) and set it size to freeform in attribute inspector and change its frame's width and height to your required values and add view components
it will show the view controller with width and height of 540*620 with your animation
that's all
- (IBAction)presentAction:(id)sender
{
TestViewController *testVc = [[TestViewController alloc]initWithNibName:#"TestViewController" bundle:nil];
UINavigationController *aNavController = [[UINavigationController alloc] initWithRootViewController:testVc];
aNavController.modalPresentationStyle = UIModalPresentationFormSheet;
aNavController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:aNavController animated:YES completion:nil];
}
I have this code to hide UIPickerView by default:
- (void)viewDidLoad
{
[super viewDidLoad];
[_memberList setAlpha:0];
}
and this code to show UIPickerView when a button tapped :
- (IBAction)buttonChooseMember {
[UIView animateWithDuration:0.6 delay:0. options:UIViewAnimationOptionCurveEaseInOut animations:^{
[_memberList setAlpha:1];
} completion:nil];
}
and the last thing is this, to hide keyboard when user tap anywhere :
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
for (UIView * txt in self.view.subviews){
if ([txt isKindOfClass:[UITextField class]]) {
[txt resignFirstResponder];
}else if ([txt isKindOfClass:[UIPickerView class]]) {
[UIView animateWithDuration:0.6 delay:0. options:UIViewAnimationOptionCurveEaseInOut animations:^{
[_registerMLMList setAlpha:0];
} completion:nil];
}
}
}
but all of this just give me 'appear' animation, because it's only changing Alpha value from 0 to 1 (and vice versa). not slide-up or slide-down just like iOS keyboard.
I tried to use this animation below to have iOS keyboard look and feel on my UIPickerView :
- (IBAction)hidePicker {
UIPickerView *pickerView = [[UIPickerView alloc] init]; // default frame is set
float pvHeight = pickerView.frame.size.height;
float y = _screen.bounds.size.height - (pvHeight * -2); // the root view of view controller
[UIView animateWithDuration:0.5f delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
self.picker.frame = CGRectMake(0 , y, pickerView.frame.size.width, pvHeight);
} completion:nil];
}
- (IBAction)showPicker {
UIPickerView *pickerView = [[UIPickerView alloc] init]; // default frame is set
float pvHeight = pickerView.frame.size.height;
float y = _screen.bounds.size.height - (pvHeight); // the root view of view controller
[UIView animateWithDuration:0.5f delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
self.picker.frame = CGRectMake(0 , y, pickerView.frame.size.width, pvHeight);
} completion:nil];
}
I like this animation, it looks like iOS keyboard animation, but the problem with this animation is... when my app is loaded, the UIPickerView is already shows up. how to hide it when it loads up for the first time?
thank you.
All UIResponder objects have an inputView property. The inputView of a UIResponder is the view that will be shown in place of the keyboard when the responder becomes the first responder.
So if you want a UIPickerView to show up instead of the keyboard, you could simply do it by making your UIResponder (like a UITextField) have a UIPickerView as its inputView.
(As a caveat: you probably won't want a bare UIPickerView as the inputView, because you also need to account for when the keyboard would change size, like when you rotate. But this is the general idea.)
In viewDidLoad take one boolean variable and set it's value as TRUE and also set the UIPickerView's frame so that UIPickerView is invisible for first time.Based on the boolean value handle the frame animations to show or hide the picker view.
hidepicker and showpicker method idea is good, and the problem of "UIPicker is visible when the app is loaded" can be overcome by just setting the frame of UIPickerView while initiating it to the position such that it should not be visible...after that you can call the showpicker method to show the picker view.
I can change the position of delete button when tableviewcell in the edit style, use following code
- (void)didTransitionToState:(UITableViewCellStateMask)state
{
[super didTransitionToState:state];
if(state == UITableViewCellStateShowingDeleteConfirmationMask)
{
for (UIView *v in [self subviews])
{
if([NSStringFromClass([v class]) isEqualToString:#"UITableViewCellDeleteConfirmationControl"])
{
NSLog(#"find");
CGRect f = v.frame;
deleteView = v;
NSLog(#"delete view %#",[deleteView description]);
v.backgroundColor = [UIColor grayColor];
v.frame = CGRectMake(200, 10, f.size.width, f.size.height);
UIControl *vs = [[v subviews]objectAtIndex:0];
CGRect fs = vs.frame;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1];
fs.origin.x -=20;
vs.frame = fs;
[UIView commitAnimations];
}
}
}
}
use this way I can change the position of delete button. But each time the delete button appears, it moves in from the right side of my tableviewcell with animation, and finally it located at the position I specified..... I just want to set the button frame before it appears, but now i have no idea. my english is poor ...thanks everybody ..thanks in advance
There are two messages: tableView:willBeginEditingRowAtIndexPath: and tableView:didEndEditingRowAtIndexPath:.
I think you can use the delegate to update the appearance of the table view appropriately.