This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Relative to margin | |
@"V:|-[subview]-|" | |
Relative to border | |
@"V:|-0-[subview]-0-|" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text | |
{ | |
if (text.length == 0 && range.length == 1) | |
{ | |
//backspace is pressed | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(NSInteger)indexOfTappedCharacterWithTapGesture:(UITapGestureRecognizer *)tapGesture | |
{ | |
CGPoint location = [tapGesture locationInView:self]; | |
// init text storage | |
NSTextStorage *textStorage = [[NSTextStorage alloc] initWithAttributedString: self.attributedText]; | |
NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init]; | |
[textStorage addLayoutManager:layoutManager]; | |
// init text container |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For example, tap gesture is often added to root view to dismiss keyboard on tap on the screen. | |
If the root view contains a table view, the tap gesture will block tap on the cell, | |
so didselectrowatindexpath will never be called. To let the gesturerecognizer pass touches to the view, add | |
gestureRecognizer.cancelsTouchesInView = NO; //default value is YES. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[UIViewController initWithNibName:] is only used when the view controller is created directly in code instead of in storyboard. | |
The nib file with the nib name if actually for the view of the controller (in fact there is no option for view controller when creating new User Interface file in Xcode), | |
so unarchiving the nib file will call | |
[UIView initWithCoder:] instead of [UIViewController initWithCoder:]. | |
The unarchiving will only be triggered when the view property | |
of the view controller is accessed for the first time, because [UIView initWithCoder:] is called by [UIViewController loadView]. | |
On the other hand, when UIViewController is created in storyboard, either automatically by storyboard or manually by calling | |
[UIStoryboard instantiateViewControllerWithItentifier:], | |
[UIViewController initWithCoder:] will be called to unarchive the view controller object from the storyboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[UIView setAnimationsEnabled: NO]; | |
[button setTitle: @"New Title" forState:UIControlStateNormal]; | |
[button layoutIfNeeded]; //why is this needed? | |
[UIView setAnimationsEnabled: YES]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xib does not automatically unarchive embedded xib. So simply setting a subview's class in IB to another xib's class won't work. | |
Need to manually load the embedded xib in -initWithCoder:. | |
Note that the subview object just loaded needs to be manually added to the view hirerachy. | |
One trick is to have a wrapper view of the subview to be embedded in the prarent xib. | |
The wrapper view's layout can be easily setup in the parent xib. | |
Then in the code, simply add the subview object to the wrapper view in -awakeFromNib: | |
And it's very easy to setup the subview's constraints to take up the wrapper view. | |
In -initWithCoder: the IBOutlets have not been connected, so any IBOutlet property is nil in -initWithCoder: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Suppose we have a presenting vc, vca, and a presented vc, vcb | |
If vca presentes vcb with UIModalPresentationFullScreen style, | |
vca's view will be moved to | |
transitionContext's containerView. During the transition animation | |
vcb's view is added on top of vca's view to the containerView. After the trainsition completes vca's view | |
is removed from the containerView, and vca has disappeared. During the dismissing trainsion, vca's view has to be | |
inserted to the containerView beneath vcb's view, so that vca's view will be revealed | |
as vcb's view moves off screen. If vca's view is not inserted back to containerView, a | |
black screen will be displayed at the end of the transition before vca's view appears. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ssh to node server | |
sudo apt-get update | |
sudo apt-get install git nodejs npm supervisor | |
ssh to mongodb server | |
sudo vi /etc/mongod.conf | |
change binip to 0.0.0.0 | |
on dev terminal | |
gcloud compute firewall-rules create default-allow-mongo \ |