Focus bar is animating faster than keyboard in iOS 7 - ios

I am implementing a custom focus bar on top of my keyboard. The focus bar has widgets to move cursor back and forward along with a done button.
Now, with iOS 7, I am seeing the focus bar is moving faster than keyboard. Because of this for a second I see screen behind the focus bar before it sits on top of keyboard. This is working fine in iOS 6.
Below is what I am doing:
- (void)keyboardWillShow:(NSNotification *)iNotification {
self.dismissForm = NO;
self.shouldScrollCell = YES;
CGFloat aKeyboardAnimationDuration = [[iNotification userInfo][UIKeyboardAnimationDurationUserInfoKey] doubleValue];
CGRect aKeyboardFrame = [[iNotification userInfo][UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGRect adjustedKeyboardFrame = [self.view convertRect:aKeyboardFrame fromView:nil];
CGFloat adjustedHeight;
adjustedHeight = aKeyboardFrame.size.height + self.focusControlBar.frame.size.height;
[self.focusControlBar viewForFocusControlWillShowWithEndFrame:adjustedKeyboardFrame andAnimationDuration:aKeyboardAnimationDuration];
[UIView animateWithDuration:0.3 animations:^() {
[self.tableView setContentInset:UIEdgeInsetsMake(kScreenOrigin, kScreenOrigin, adjustedHeight, 0.0f)];
[self.tableView setScrollIndicatorInsets:UIEdgeInsetsMake(kScreenOrigin, kScreenOrigin, adjustedHeight, 0.0f)];
}];
}
This is my focus bar animation code:
- (void)viewForFocusControlWillShowWithEndFrame:(CGRect)iFrame andAnimationDuration:(CGFloat)iDuration {
BOOL aShouldAppear = YES;
if (self.delegate && [self.delegate respondsToSelector:#selector(focusControlBarShouldAppear:)]) {
aShouldAppear = [self.delegate focusControlBarShouldAppear:self];
}
if (aShouldAppear) {
if (self.delegate && [self.delegate respondsToSelector:#selector(focusControlBarWillAppear:)]) {
[self.delegate focusControlBarWillAppear:self];
}
CGRect aBarFrame = self.frame;
UIInterfaceOrientation anInterfaceOrientation = [UIApplication sharedApplication].statusBarOrientation;
aBarFrame.size.height = [self heightForOrientation:anInterfaceOrientation];
self.frame = aBarFrame;
aBarFrame.origin.y = self.superview.bounds.size.height - iFrame.size.height - aBarFrame.size.height;
[UIView animateWithDuration:iDuration animations:^(void) {
self.frame = aBarFrame;
} completion:^(BOOL iFinished) {
if (self.delegate && [self.delegate respondsToSelector:#selector(focusControlBarDidAppear:)]) {
[self.delegate focusControlBarDidAppear:self];
}
}];
}
}

I just got to know that with iOS 7 we need to also keep KeyboardAnimationCurve into account. With the below modified code I had it worked.
- (void)keyboardWillShow:(NSNotification *)iNotification {
self.dismissForm = NO;
self.shouldScrollCell = YES;
NSDictionary *aNotificationInfo = [iNotification userInfo];
CGFloat aKeyboardAnimationDuration = [aNotificationInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
UIViewAnimationCurve aKeyboardAnimationCurve = [aNotificationInfo[UIKeyboardAnimationCurveUserInfoKey] intValue];
CGRect aKeyboardFrame = [aNotificationInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGRect adjustedKeyboardFrame = [self.view convertRect:aKeyboardFrame fromView:nil];
CGFloat adjustedHeight;
adjustedHeight = aKeyboardFrame.size.height + self.focusControlBar.frame.size.height;
[self.focusControlBar viewForFocusControlWillShowWithEndFrame:adjustedKeyboardFrame animationCurve:aKeyboardAnimationCurve andAnimationDuration:aKeyboardAnimationDuration];
[UIView animateWithDuration:0.3 animations:^() {
[self.tableView setContentInset:UIEdgeInsetsMake(kScreenOrigin, kScreenOrigin, adjustedHeight, 0.0f)];
[self.tableView setScrollIndicatorInsets:UIEdgeInsetsMake(kScreenOrigin, kScreenOrigin, adjustedHeight, 0.0f)];
}];
}
- (void)viewForFocusControlWillShowWithEndFrame:(CGRect)iFrame animationCurve:(UIViewAnimationCurve)iAnimationCurve andAnimationDuration:(CGFloat)iDuration {
BOOL aShouldAppear = YES;
if (self.delegate && [self.delegate respondsToSelector:#selector(focusControlBarShouldAppear:)]) {
aShouldAppear = [self.delegate focusControlBarShouldAppear:self];
}
if (aShouldAppear) {
if (self.delegate && [self.delegate respondsToSelector:#selector(focusControlBarWillAppear:)]) {
[self.delegate focusControlBarWillAppear:self];
}
CGRect aBarFrame = self.frame;
UIInterfaceOrientation anInterfaceOrientation = [UIApplication sharedApplication].statusBarOrientation;
aBarFrame.size.height = [self heightForOrientation:anInterfaceOrientation];
self.frame = aBarFrame;
aBarFrame.origin.y = self.superview.bounds.size.height - iFrame.size.height - aBarFrame.size.height;
[UIView animateWithDuration:iDuration delay:0.0 options:(iAnimationCurve << 16) animations:^{
self.frame = aBarFrame;
} completion:^(BOOL finished) {
if (self.delegate && [self.delegate respondsToSelector:#selector(focusControlBarDidAppear:)]) {
[self.delegate focusControlBarDidAppear:self];
}
}];
}
}

Related

iPad - Objective - C - Keyboard - Everything moves from left to right, not down to up

I hope this question makes sense, I have a login screen, when I click on the one of my input fields (either Username or Password) a keyboard appears. but when that happens Everything moves in motion from left to right, so I have a big white space on the left side. What I am expecting is for everything to move from down to up instead. I really hope this makes sense. Here is my code:
- (void)animateTextField:(UITextField *) textField up: (BOOL) up;
- (void)NavButtonPressed: (UIButton*)sender;
- (void)NavButtonPressed: (UIButton*)sender
{
if([sender isEqual:navBarNextButton])
{
[self.idTextField resignFirstResponder];
[self.passwordTextField becomeFirstResponder];
currentResponder = 1;
[self animateTextField:self.passwordTextField up:NO];
[self animateTextField:self.passwordTextField up:YES];
[navBarNextButton setEnabled:NO];
[navBarPrevButton setEnabled:YES];
}
else
{
[self.passwordTextField resignFirstResponder];
[self.idTextField becomeFirstResponder];
currentResponder = 0;
[self animateTextField:self.idTextField up:NO];
[self animateTextField:self.idTextField up:YES];
[navBarNextButton setEnabled:YES];
[navBarPrevButton setEnabled:NO];
}
}
- (void)animateTextField:(UITextField *) textField up: (BOOL) up
{
int movementDistance;
if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
{
if([textField isEqual:self.idTextField])
{
[textfieldNavigatorView setFrame:CGRectMake(0.0f, (1024.0f/2.0f)-31.5f, 1024.0f, 45.0f)];
movementDistance = 110;
}
else
{
[textfieldNavigatorView setFrame:CGRectMake(0.0f, (1024.0f/2.0f)-26.5f, 1024.0f, 45.0f)];
movementDistance = 115;
}
}
else
{movementDistance = 0;}
const float movementDuration = 0.3f;
int movement=0;
if([self interfaceOrientation] == UIInterfaceOrientationLandscapeLeft)
movement = (up? -movementDistance : movementDistance);
if([self interfaceOrientation] == UIInterfaceOrientationLandscapeRight)
movement = (up? movementDistance : -movementDistance);
[UIView beginAnimations:#"keyboardtransition" context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:movementDuration];
self.view.frame = CGRectOffset(self.view.frame, movement, 0);
[UIView commitAnimations];
}
If anyone could help, that would be amazing. My project Device is set to Landscape Right only.
I had same issue before, in iOS 7 and 8 it works differently. So I implemented a method for handling the issue:
- (void)keyboardHideShow:(UIView *)view shiftBy:(float)shiftAmount forState:(BOOL)state
{
float keyBoardOffset = shiftAmount;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3]; // if you want to slide up the view
[UIView setAnimationBeginsFromCurrentState:YES];
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
CGRect rect = [[[UIApplication sharedApplication] keyWindow] bounds];
if (state)
{
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8)
{
if (orientation == UIInterfaceOrientationLandscapeLeft)
{
rect.origin.x -= keyBoardOffset;
}
else
{
rect.origin.x += keyBoardOffset;
}
}
else
{
rect.origin.y -= keyBoardOffset;
}
}
view.frame = rect;
[UIView commitAnimations];
}
You can call it like:
[self keyboardHideShow:textfieldNavigatorView shiftBy:31.5 forState:true]; // For up
[self keyboardHideShow:textfieldNavigatorView shiftBy:31.5 forState:false]; // For down

Animations in TableView in Ios

I have a tableview with a hidden property. I want to unhide it with animation so that it could slide from bottom to top? Any suggestions please.
-(IBAction) hideTable : (id) sender;
{
if(self.tb.hidden==true)
{
self.tb.alpha=1;
[self.tb setHidden:NO];
}
else{
[self.tb setHidden:YES];
}
}
-(IBAction) hideTable : (id) sender{
if (self.sessionView.hidden == YES) {
// Currently NOT Visible. Show it now
// First unhide it
yourTableView.hidden = NO;
[UIView animateWithDuration:0.5f
animations:^{
// Get the Existing table View frame
CGRect hiddenFrame = yourTableView.frame;
// Reset it to 0 or your own value
hiddenFrame.origin.y = 0;
// Set the new frame
yourTableView.frame = hiddenFrame;
} completion:^(BOOL finished) {
NSLog(#"Shown");
}];
}
else{
// Currently Visible. Hide it Now
[UIView animateWithDuration:0.5f
animations:^{
// Get the Existing table View frame
CGRect hiddenFrame = yourTableView.frame;
// Under the superview height
hiddenFrame.origin.y = yourTableView.superview.frame.size.height;
// Set the new frame
yourTableView.frame = hiddenFrame;
} completion:^(BOOL finished) {
yourTableView.hidden = YES;
NSLog(#"Hidden");
}];
}
}
try this
CGRect frame = self.tb.frame;
if (self.tb.hidden) {
CGRect temp_frame = frame;
frame.size.height = 1;
self.tb.frame = temp_frame;
self.tb.hidden = NO;
[UIView animateWithDuration:0.3
animations:^{
self.tb.frame = frame;
} completion:^(BOOL finished) {
}];
}
else
{
[UIView animateWithDuration:0.3
animations:^{
CGRect temp_frame = frame;
frame.size.height = 1;
self.tb.frame = temp_frame;
} completion:^(BOOL finished) {
self.tb.hidden = YES;
}];
}
try this
-(IBAction) hideTable : (id) sender;
{
if(self.tb.hidden==true)
{
self.tb.alpha=1;
[self.tb setHidden:NO];
[UIView animateWithDuration:.25
animations:^{
self.tb.frame = CGRectMake(0,50,320,400); // your req frame
}
];
}
else
{
[UIView animateWithDuration:0.35
animations:^{
self.tb.frame = CGRectMake(0, self.view.frame.size.height+10, 320,400); // y point of yor tableview is more than view bounds so it goes down
}
completion:^(BOOL finished){
[self.tb setHidden:YES];
}
];
}
}
You can use the below methods:
1. (void)showDropDownTable:- To show tableview with top to bottom animation.
2. (void)hideDropdownTable:- To hide tableview with bottom to top animation.
- (IBAction)btnDropDownClicked:(id)sender
{
if (checkShowHideTableView == TRUE)
{
[self hideTableView];
}
if (self.tblDropDown.hidden)
{
[self showDropDownTable];
}
else
{
[self hideDropdownTable];
}
}
- (void)showDropDownTable
{
[UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationCurveEaseOut animations: ^{
_tblDropDown.frame = CGRectMake(self.tblDropDown.frame.origin.x, self.tblDropDown.frame.origin.y, self.tblDropDown.frame.size.width, kDropdownTableHeight);
self.tblDropDown.hidden = FALSE;
} completion: ^(BOOL finished) {
}];
}
- (void)hideDropdownTable
{
[UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationCurveEaseOut animations: ^{
_tblDropDown.frame = CGRectMake(self.tblDropDown.frame.origin.x, self.tblDropDown.frame.origin.y, self.tblDropDown.frame.size.width, 0);
} completion: ^(BOOL finished) {
self.tblDropDown.hidden = TRUE;
}];
}
Hope this can help you.
Try the following
[self.tb beginUpdates];
[UIView animateWithDuration:0.5
delay:0.1
options:(UIViewAnimationCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction)
animations:^{
if(self.tb.isHidden)
{
self.tb.alpha=1;
[self.tb setHidden:NO];
}
else
{
self.tb.alpha=0;
[self.tb setHidden:YES];
}
}
completion:^(BOOL finished) {
}];
[self.tb endUpdates];

Blank Space above keyboard hides the text field

I am getting problem when trying to move my scroll view up when the keyboard appears.
The scroll view moves up in ios7 but in ios6 it doesn't and there is additional white space above the keyboard that hides the controls on the screen
my code:
- (void)viewWillAppear:(BOOL)animated
{
[super viewDidAppear:animated];
keyboardIsShown = NO;
[super viewWillAppear:animated];
[[self view] endEditing:YES];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:self.view.window];
// register for keyboard notifications
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:self.view.window];
}
- (void)keyboardWillShow:(NSNotification *)n
{
if (keyboardIsShown) {
return;
}
NSDictionary* userInfo = [n userInfo];
// get the size of the keyboard
CGSize keyboardSize = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
// resize the noteView
CGRect viewFrame = self.scrollView.frame;
viewFrame.size.height -= (keyboardSize.height - kTabBarHeight);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
// The kKeyboardAnimationDuration I am using is 0.3
[UIView setAnimationDuration:kKeyboardAnimationDuration];
[self.scrollView setFrame:viewFrame];
[UIView commitAnimations];
scrollView.contentSize = formView.frame.size;
keyboardIsShown = YES;
}
Whats the problem here. pls help
The problem is, that you only change size of the scroll view, but you don't tell the scrollview to scroll to the text field.
Look at my method scrollToEditingTextField for better understanding.
- (void)keyboardWillShown:(NSNotification*)aNotification
{
NSDictionary* info = [aNotification userInfo];
CGSize beginSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
// keyboard will appear
if(!_keyboardShowed) {
_keyboardShowed = YES;
[UIView animateWithDuration:0.4
animations:^{
CGFloat scrollHeight =_scrollView.size.height - (IS_PORTRAIT_ORIENTATION ? beginSize.height : beginSize.width);
CGRect scrollFrame = _scrollView.frame;
scrollFrame.size.height = scrollHeight;
_scrollView.frame = scrollFrame;
}
completion:^(BOOL finished){ }];
}
[self scrollToEditingTextField];
}
- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
NSDictionary* info = [aNotification userInfo];
CGSize endSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
// keyboard will disappear
if(_keyboardShowed) {
CGFloat scrollHeight =_scrollView.size.height + (IS_PORTRAIT_ORIENTATION ? endSize.height : endSize.width);
CGRect scrollFrame = _scrollView.frame;
scrollFrame.size.height = scrollHeight;
_scrollView.frame = scrollFrame;
_keyboardShowed = NO;
}
}
-(void)scrollToEditingTextField {
// find which text field is currently editing
UITextField *editingTextFiled = [self editingTextField:self.thisView];
if(editingTextFiled == nil) return; // text field didnt found
CGPoint scrollPoint = [editingTextFiled convertPoint:CGPointMake(0, 0) toView:self.scrollView];
scrollPoint.y -= 70;
scrollPoint.x = 0;
[_scrollView setContentOffset:scrollPoint animated:YES];
}
-(UITextField*)editingTextField:(UIView*)view
{
if( ( [[view class] isSubclassOfClass:[UITextField class]] ||
[[view class] isSubclassOfClass:[UITextView class]] ) &&
[view isFirstResponder] ) {
return (UITextField*)view;
}
for(UIView *subview in view.subviews ) {
if([[subview class] isSubclassOfClass:[UISearchBar class]]) {
return nil;
}
if( ( [[subview class] isSubclassOfClass:[UITextField class]] ||
[[subview class] isSubclassOfClass:[UITextView class]] ) &&
[subview isFirstResponder] ) {
return (UITextField*)subview;
}
}
// recursion
for(UIView *subview in view.subviews ) {
UITextField *textField = [self editingTextField:subview];
if(textField) return textField;
}
return nil;
}

How to customize iPad keyboard appearance from the right side of the screen?

I made a custom keyboard using UITextField method inputView. That works perfectly. But the keyboard shows as a normal keyboard from the bottom of the screen. I would like to animate the keyboard appearance from the right side of the screen.
Is that even possible ?
Thanks for any help!
I ended up with coding my own keyboard.
If somebody is interested:
#interface Keyboard ()
#property (assign, readwrite) BOOL visible;
#property (nonatomic, strong) UITextField *editingTextInput;
#property (nonatomic, strong) UIView *blockingView;
#end
#implementation Keyboard
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self addObservers];
self.exclusiveTouch = YES;
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
[self addObservers];
self.exclusiveTouch = YES;
}
return self;
}
#pragma mark Register for notifications
- (void)addObservers {
// Keep track of the textView/Field that we are editing
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(editingDidBegin:)
name:UITextFieldTextDidBeginEditingNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(editingDidBegin:)
name:UITextViewTextDidBeginEditingNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(editingDidEnd:)
name:UITextFieldTextDidEndEditingNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(editingDidEnd:)
name:UITextViewTextDidEndEditingNotification
object:nil];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UITextFieldTextDidBeginEditingNotification
object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UITextViewTextDidBeginEditingNotification
object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UITextFieldTextDidEndEditingNotification
object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UITextViewTextDidEndEditingNotification
object:nil];
}
-(BOOL)isKeyboardForTextField:(UITextField*)textField
{
// need to be implemented at child object
return NO;
}
#pragma mark Show In View
static UIView *showInView;
+(void)setShowInView:(UIView *)view {
showInView = view;
}
+(UIView*)showInView {
return showInView;
}
#pragma mark Notifications - editing DidBegin/End
// Editing just began, store a reference to the object that just became the firstResponder
- (void)editingDidBegin:(NSNotification *)notification {
if ([notification.object isKindOfClass:[UIResponder class]])
{
if ([notification.object conformsToProtocol:#protocol(UITextInput)]) {
if([self isKeyboardForTextField:notification.object]) {
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:#selector(hideKeyboard) object:nil];
_targetTextInput = notification.object;
_targetTextInput.inputView = [[UIView alloc] initWithFrame:CGRectNull];;
if(!_visible) {
[self showKeyboard];
}
}
return;
}
}
// Not a valid target for us to worry about.
_targetTextInput = nil;
}
// Editing just ended.
- (void)editingDidEnd:(NSNotification *)notification {
[self performSelector:#selector(hideKeyboard) withObject:nil afterDelay:0.1]; // so we have chance to stop it
}
#pragma mark Show / Hide keyboard
-(void)enableUserInteraction {
[_blockingView removeFromSuperview];
}
-(void)disableUserInteraction {
_blockingView = [[UIView alloc] initWithFrame:[Keyboard showInView].frame];
_blockingView.backgroundColor = [UIColor clearColor];
[[Keyboard showInView] addSubview:_blockingView];
}
- (void)showKeyboardWithAnimation:(BOOL)animation
{
[[Keyboard showInView] addSubview:self];
_visible = NO;
[self disableUserInteraction];
if (IS_IPHONE)
{
[self setOrigin:CGPointMake(0, [Keyboard showInView].size.height)];
[self updateBackground];
[UIView animateWithDuration:( animation ? .2 : 0)
delay:0.0
options: UIViewAnimationOptionBeginFromCurrentState
animations:^(void){
[self moveOriginY:-self.size.height];
}
completion:^(BOOL finished){
_visible = YES;
[self enableUserInteraction];
}];
} else {
[self setOrigin:CGPointMake([Keyboard showInView].size.width, [Keyboard showInView].size.height - self.size.height - 10)];
[UIView animateWithDuration:( animation ? .5 : 0)
delay:0.0
options: UIViewAnimationOptionBeginFromCurrentState
animations:^(void){
[self moveOriginX:-self.size.width];
}
completion:^(BOOL finished){
_visible = YES;
[self enableUserInteraction];
}];
}
}
-(void)showKeyboard
{
[self showKeyboardWithAnimation:YES];
}
- (void)hideKeyboardWithAnimation:(BOOL)animation
{
[self disableUserInteraction];
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) {
[UIView animateWithDuration:( animation ? .2 : 0)
delay:0.0
options: UIViewAnimationOptionBeginFromCurrentState
animations:^(void){
[self moveOriginY:self.size.height];
}
completion:^(BOOL finished){
[self removeFromSuperview];
_visible = NO;
[self enableUserInteraction];
}];
} else {
[UIView animateWithDuration:( animation ? .5 : 0)
delay:0.0
options: UIViewAnimationOptionBeginFromCurrentState
animations:^(void){
[self moveOriginX:self.size.width];
}
completion:^(BOOL finished){
[self removeFromSuperview];
_visible = NO;
[self enableUserInteraction];
}];
}
}
-(void)hideKeyboard
{
[self hideKeyboardWithAnimation:YES];
}
#end
UIView categories:
#implementation UIView (Frame)
-(CGPoint)origin {
return self.frame.origin;
}
-(CGSize)size {
return self.frame.size;
}
#pragma mark Change Origin
-(void)setOrigin:(CGPoint)origin
{
CGRect frame = self.frame;
frame.origin = origin;
self.frame = frame;
}
-(void)setOriginX:(CGFloat)x
{
CGRect frame = self.frame;
frame.origin.x = x;
self.frame = frame;
}
-(void)setOriginY:(CGFloat)y
{
CGRect frame = self.frame;
frame.origin.y = y;
self.frame = frame;
}
#pragma mark Move Origin
-(void)moveOrigin:(CGPoint)origin
{
CGRect frame = self.frame;
frame.origin.y += origin.y;
frame.origin.x += origin.x;
self.frame = frame;
}
-(void)moveOriginX:(CGFloat)x
{
CGRect frame = self.frame;
frame.origin.x += x;
self.frame = frame;
}
-(void)moveOriginY:(CGFloat)y
{
CGRect frame = self.frame;
frame.origin.y += y;
self.frame = frame;
}
#pragma mark Change Size
-(void)setSize:(CGSize)size
{
CGRect frame = self.frame;
frame.size = size;
self.frame = frame;
}
-(void)setSizeWidth:(CGFloat)width
{
CGRect frame = self.frame;
frame.size.width = width;
self.frame = frame;
}
-(void)setSizeHeight:(CGFloat)height
{
CGRect frame = self.frame;
frame.size.height = height;
self.frame = frame;
}
#pragma mark Change Size
-(void)addSizeWidth:(CGFloat)width
{
CGRect frame = self.frame;
frame.size.width += width;
self.frame = frame;
}
-(void)addSizeHeight:(CGFloat)height
{
CGRect frame = self.frame;
frame.size.height += height;
self.frame = frame;
}
#end

Options appear when tap on UIImageView

In Apple iOs photos app, Each picture take the full screen, but when You tap on it, navigation bar and tab bar with some menu options (like share picture) just appear and remain for a couple of secconds. How can I do that in my UIImageView ?
Add a UITapGestureRecognizer to your view and UiView for your topbar and bottom bar or what else you like and follow below code. I think This may help you.
//Write below code in ViewDidLoad
UITapGestureRecognizer *singleTapOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleSingleTap:)];
singleTapOne.numberOfTouchesRequired = 1; singleTapOne.numberOfTapsRequired = 1; singleTapOne.delegate = self;
[self.view addGestureRecognizer:singleTapOne]; [singleTapOne release];
for (UIGestureRecognizer *gR in self.view.gestureRecognizers) {
gR.delegate = self;
// handleSingleTap Method
- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer
{
if (recognizer.state == UIGestureRecognizerStateRecognized)
{
CGRect viewRect = recognizer.view.bounds; // View bounds
CGPoint point = [recognizer locationInView:recognizer.view];
CGRect areaRect = CGRectInset(viewRect, TAP_AREA_SIZE, 0.0f); // Area
if (CGRectContainsPoint(areaRect, point)) // Single tap is inside the area
{
if ((m_CtrlViewTopBar.hidden == YES) || (m_CtrlViewBottomBar.hidden == YES))
{
[self showToolbar:m_CtrlViewTopBar];
[self showToolbar:m_CtrlViewBottomBar]; // Show
}
else
{
[self hideToolbar:m_CtrlViewTopBar];
[self hideToolbar:m_CtrlViewBottomBar];
}
return;
}
CGRect nextPageRect = viewRect;
nextPageRect.size.width = TAP_AREA_SIZE;
nextPageRect.origin.x = (viewRect.size.width - TAP_AREA_SIZE);
if (CGRectContainsPoint(nextPageRect, point)) // page++ area
{
//[self incrementPageNumber]; return;
}
CGRect prevPageRect = viewRect;
prevPageRect.size.width = TAP_AREA_SIZE;
if (CGRectContainsPoint(prevPageRect, point)) // page-- area
{
//[self decrementPageNumber]; return;
}
}
}
- (void)hideToolbar:(UIView*)view //Hide Toolbars
{
#ifdef DEBUGX
NSLog(#"%s", __FUNCTION__);
#endif
if (view.hidden == NO)
{
[UIView animateWithDuration:0.25 delay:0.0
options:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction
animations:^(void)
{
view.alpha = 0.0f;
}
completion:^(BOOL finished)
{
view.hidden = YES;
}
];
}
[timer invalidate];
timer=nil;
}
- (void)showToolbar:(UIView*)view //Show Toolbars
{
#ifdef DEBUGX
NSLog(#"%s", __FUNCTION__);
#endif
if (view.hidden == YES)
{
[UIView animateWithDuration:0.25 delay:0.0
options:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction
animations:^(void)
{
view.hidden = NO;
view.alpha = 1.0f;
}
completion:NULL
];
if (!timer) {
timer=[NSTimer scheduledTimerWithTimeInterval:5
target:self
selector:#selector(HideToolBarWithTime)
userInfo:nil
repeats:YES];
}
}
[self.view addSubview:view];
}
-(void)HideToolBarWithTime //Hide Toolbars with time
{
[self hideToolbar:m_CtrlViewTopBar];
[self hideToolbar:m_CtrlViewBottomBar];
[timer invalidate];
timer=nil;
}
// Gesture Delegates
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
return YES;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}

Resources