1、如果子視圖想push一個(gè)控制器,而子視圖中拿不到navigationController 怎么辦
2、圖片的拉伸,當(dāng)圖片被拉伸后,當(dāng)前空缺的地方是copy這個(gè)設(shè)置的像素點(diǎn)
3、 KVO(觀察者)的使用。
4、collectionView的邊緣值,我用的xcode7反正這個(gè)方法我是沒找到
5、用storyboard創(chuàng)建的cell是不用注冊(cè)也不用判斷是否為空
1、 如果子視圖想push一個(gè)控制器,而子視圖中拿不到navigationController 怎么辦
解決辦法一
//取出根視圖控制器
UITabBarController *tabBarVc = (UITabBarController *)[UIApplication sharedApplication].keyWindow.rootViewController;
//取出當(dāng)前選中的導(dǎo)航控制器
UINavigationController *Nav = [tabBarVc selectedViewController];
[Nav pushViewController:topDetailView animated:YES];
解決辦法二
// 給UIView 寫個(gè)分類
/** 實(shí)現(xiàn)子視圖push到控制器 */
- (UIViewController *)viewController {
for (UIView* next = [self superview]; next; next = next.superview) {
UIResponder* nextResponder = [next nextResponder];
if ([nextResponder isKindOfClass:[UIViewController class]]) {
return (UIViewController*)nextResponder;
}
}
return nil;
}
// 然后就可以這樣使用
[self.viewController.navigationController pushViewController:topDetailView animated:YES];
2、 圖片的拉伸,當(dāng)圖片被拉伸后,當(dāng)前空缺的地方是copy這個(gè)設(shè)置的像素點(diǎn)
// 圖片拉伸
UIImage *image = [UIImage imageNamed:@"indexBG_home"];
UIImage *stresImage = [image stretchableImageWithLeftCapWidth:0 topCapHeight:1];
headView.image = stresImage;
3、KVO(觀察者)的使用。
// 添加觀察者
[self.smallView addObserver:self
forKeyPath:@"index" // 監(jiān)聽的值
options:NSKeyValueObservingOptionNew
context:nil];
#pragma mark - 觀察者
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context {
NSInteger index = [[change objectForKey:@"new"]integerValue];
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:index inSection:0];
[UIView animateWithDuration:0.35 animations:^{
[self.posterView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
}];
}
#pragma mark - 手動(dòng)移除觀察者
- (void) dealloc {
[self.smallView removeObserver:self forKeyPath:@"index"];
}
4、collectionView的邊緣值,我用的xcode7反正這個(gè)方法我是沒找到
#pragma mark - UICollectionViewDelegateFlowLayout
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
return UIEdgeInsetsMake(0, 50, 0, 50);
}