Tag Archives: iOS

Cocoapods xcode 5 problem.

Archive Error for cocoapods project created from xcode 4 – Library not found for lpods.


Step 1. Set ‘Build Active Architecture Only’ to ‘No’ for both build and release.

Step 2. Remove ‘arm64’ from ‘Valid Architectures’.

Leave a comment

Posted by on December 24, 2013 in iPhone


Tags: ,

Adjust view content when keyboard is shown

Step 1. Create a KeyboardDisplayProtocol (KeyboardDisplayProtocol.h):

#import <Foundation/Foundation.h>

@protocol KeyboardDisplayProtocol <NSObject>

– (void)registerForKeyboardNotifications;
– (void)unregisterForKeyboardNotifications;
– (void)keyboardWasShown:(NSNotification *)aNotification;
– (void)keyboardWillBeHidden:(NSNotification *)aNotification;


Step 2. Declare your ViewController to extend the protocol. Add an ivar to track the textfield user has clicked. (MyViewController.h)

@interface MyViewController : UIViewController <KeyboardDisplayProtocol>
UITextField *m_activeField;

Step 3. Implement the protocol methods in MyViewController.m

#pragma mark –
#pragma mark KeyboardDisplay Delegate
– (void)registerForKeyboardNotifications
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeHidden:) name:UIKeyboardWillHideNotification object:nil];

– (void)unregisterForKeyboardNotifications
[[NSNotificationCenter defaultCenter] removeObserver:self];

– (void)keyboardWasShown:(NSNotification *)aNotification
NSDictionary *info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
self.profileTableView.contentInset = contentInsets;
self.profileTableView.scrollIndicatorInsets = contentInsets;

CGRect aRect = self.profileTableView.frame;
aRect.size.height -= kbSize.height;

CGPoint fieldOrigin = m_activeField.frame.origin;

fieldOrigin = CGPointMake([[m_activeField superview] superview].frame.origin.x + fieldOrigin.x, [[m_activeField superview] superview].frame.origin.y + fieldOrigin.y);

if ( !CGRectContainsPoint(aRect, fieldOrigin) )
CGPoint scrollPoint = CGPointMake(0.0, fieldOrigin.y – kbSize.height + 2 * m_activeField.frame.size.height);
[scrollView setContentOffset:scrollPoint animated:YES];

– (void)keyboardWillBeHidden:(NSNotification *)aNotification
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
scrollView.contentInset = contentInsets;
scrollView.scrollIndicatorInsets = contentInsets;

Note: You might need to customize the code base on your view hirarchy.
The two places you might need to change:
1. Replace “scrollView” with your view which is going to be scrolled
2. Replace “[[m_activeField superview] superview].frame.origin.x” with something you can calculate the clicked textfield y position in your view.

Step 4. Register and unregister keyboard events

– (void)viewWillAppear:(BOOL)animated
[super viewWillAppear:animated];

[self registerForKeyboardNotifications];

– (void)viewWillDisappear:(BOOL)animated
[super viewWillDisappear:animated];

[self unregisterForKeyboardNotifications];

That’s it! Try it out!

Leave a comment

Posted by on May 17, 2012 in iPhone, Uncategorized