散散心得
(1)在弹出视图上加层模板,很多时候就在需要用的界面上才加载的,比较麻烦一点,最近看了某个大神的demo,略有体会,
-(void)show
{
self.handerView = [UIButtonbuttonWithType:UIButtonTypeCustom];
[_handerViewsetFrame:[UIScreenmainScreen].bounds];
[_handerViewsetBackgroundColor:[UIColorclearColor]];
[_handerViewaddTarget:selfaction:@selector(dismiss)forControlEvents:UIControlEventTouchUpInside];
[_handerViewaddSubview:self];
UIWindow *window = [UIApplicationsharedApplication].keyWindow;//获取app的窗口
[window addSubview:_handerView];
//self.handerView就是膜层,是一个button,自带有点击事件,可以设置背景颜色。
CGPoint arrowPoint = [selfconvertPoint:self.showPointfromView:_handerView];
self.layer.anchorPoint =CGPointMake(arrowPoint.x /self.frame.size.width, arrowPoint.y /self.frame.size.height);
self.frame = [selfgetViewFrame];
self.alpha = 0.f;
self.transform =CGAffineTransformMakeScale(0.1f,0.1f);
[UIViewanimateWithDuration:0.2fdelay:0.foptions:UIViewAnimationOptionCurveEaseInOutanimations:^{
self.transform =CGAffineTransformMakeScale(1.05f,1.05f);
self.alpha =1.f;
} completion:^(BOOL finished) {
[UIViewanimateWithDuration:0.08fdelay:0.foptions:UIViewAnimationOptionCurveEaseInOutanimations:^{
self.transform =CGAffineTransformIdentity;
} completion:nil];
}];
}
(2)比如说,view1 和view2,我们需要在[view1 addSubview:view2],一般时候我们都是在view1界面上进行操作,但是否想过,将view1以参数形式,在view2类中进行操作,这样我们就可以省略了每次的addsubview,尤其对于那些要在不同界面上加载的视图(比如:请求时的加载动画等)。
(3)开始对块产生了兴趣,也不知道该如何说起,直接说列子吧,。。,,
@interface PopoverView : UIView
//也定义了一个块,目的是为了获取tableview到底点击某一行
@property (nonatomic,copy) void (^selectRowAtIndex)(NSInteger index);
@end
@implementation PopoverView
//也只需要在下面方法中给块传值就可以了。。。
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPathanimated:NO];
if (self.selectRowAtIndex) {
self.selectRowAtIndex(indexPath.row);
}
}
接下来我们在别的地方创建PopoverView对象的时候,就可以调用定义的块来执行操作了,
//先创建对象,就这样简单,避免了复杂的值传递,简单了很多柚木YY。。。。
PopoverView *pop = [[PopoverViewalloc] initWithPoint:point titles:titles images:images];
pop.selectRowAtIndex = ^(NSInteger index){
NSLog(@"select index:%d", index);
};