1.当你的看视频 的时候 返回 HOME 再返回视频 保持视频暂停的方法
//到你的视频控制器的类中写这个方法
- (void)viewDidLoad
{
[super viewDidLoad];
// 移除程序进入后台的通知
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil];
}
2.label的动态size
- (CGSize)labelAutoCalculateRectWith:(NSString*)text FontSize:(CGFloat)fontSize MaxSize:(CGSize)maxSize
{
NSMutableParagraphStyle* paragraphStyle = [[NSMutableParagraphStyle alloc]init];
paragraphStyle.lineBreakMode=NSLineBreakByWordWrapping;
NSDictionary* attributes =@{NSFontAttributeName:[UIFont fontWithName:@"MicrosoftYaHei" size:fontSize],NSParagraphStyleAttributeName:paragraphStyle.copy};
CGSize labelSize = [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading|NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
labelSize.height=ceil(labelSize.height);
return labelSize;
}
3.时间戳转化为时间
-(NSString*)TimeTrasformWithDate:(NSString *)dateString
{
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"YY-MM-dd HH:mm"];
[formatter setTimeZone:[NSTimeZone timeZoneWithName:@"Asia/Beijing"]];
NSString *date = [formatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:dateString.integerValue]];
//NSLog(@"date1:%@",date);
return date;
}
就是只是点击cell后面的箭头或者其他标记的时候会触发动作
-(void)tableview: (UITableView *)tableview accessoryButtonTappedForRowWithIndexPath: (NSIndexPath*)indexPath。
4.键盘弹出整体上移
使用UITextFieldDelegate方法
1.键盘将要出现的时候
-(BOOL)textfieldShouldBegainEditing:(UITextField *)textfield {
//不一定所有的textfield 都被挡住了 你可以选择性的当使用到那个textfield的时候在走这个方法 我假设一个输入框 regEmail
if (self.regEmail == textfield){
//还可以加上动画
[UIView beginAnimations:@"up" context:nil];
CGRect r = self.view.frame;
r.orgin.y = -40;//这个40 是上移多少的高度 你也可以自己看看实际需要多少
self.view.frame = r;
[UIView commitAnimations];
}
return YES;
}
2.当键盘消失的时候,我们要让页面恢复原样;
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
if (self.regEmail == textField){
[UIView beginAnimations:@"up" context:nil];
CGRect r = self.view.frame;
r.orgin.y = 0;
self.view.frame = r;
[UIView commitAnimations];
}
return YES;
}
5 动态限制textfield输入
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if (textField == self.regEmail) {
NSString *reg = [textField.text stringByReplacingCharactersInRange:range withString:string];
if (reg.length >10){
return NO;
}
}
return YES;
}