UIView *view = ({
UIView *videoView = [UIView new];
videoView.backgroundColor = [UIColor clearColor];
CGFloat screenWid = [UIScreen mainScreen].bounds.size.width;
videoView.frame = CGRectMake(0, 100, screenWid, screenWid * 9.0 / 16.0);
[self.view addSubview:videoView];
videoView;
});
指针赋值有错误吧,应该是这样
创建view,等同于alloc init。用 ({ }) 里面的代码块创建一个对象,在代码块的最后一行返回对象。
你的代码和下列代码是等效的,只是不同的写法。
UIView *view = [UIView new];
view.backgroundColor = [UIColor clearColor];
CGFloat screenWid = [UIScreen mainScreen].bounds.size.width;
view.frame = CGRectMake(0, 100, screenWid, screenWid * 9.0 / 16.0);
[self.view addSubview:view];
等同于创建了一个view,只不过是写法不一样
https://github.com/liyuunxiangGit
意思就是:创建一个videoView,view = videoView