convertRect

rectrect所在视图转换到目标视图view中,返回在目标视图view中的rect

     这里用来获取selfwindow上的位置

- (CGRect)convertRect:(CGRect)rect toView:(nullable UIView *)view;

     

例如:在cell中调用

 CGRect toWindow = [self convertRect:self.bounds toView:self.window];

toWindow为相对于屏幕的位置
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您好!感谢您的问题。下面是 Objective-C 实现的具体步骤: 1. 在控制器中创建一个 UIView,命名为 displayView,并设置其 frame 为控制器的 view 的 bounds。 ``` UIView *displayView = [[UIView alloc] initWithFrame:self.view.bounds]; [self.view addSubview:displayView]; ``` 2. 在 displayView 上添加一个按钮,命名为 fullScreenButton。 ``` UIButton *fullScreenButton = [UIButton buttonWithType:UIButtonTypeSystem]; [fullScreenButton setTitle:@"全屏" forState:UIControlStateNormal]; fullScreenButton.frame = CGRectMake(0, 0, 100, 50); [fullScreenButton addTarget:self action:@selector(fullScreenAction:) forControlEvents:UIControlEventTouchUpInside]; [displayView addSubview:fullScreenButton]; ``` 3. 实现 fullScreenAction: 方法来控制 displayView 的横屏并全屏显示以及恢复竖屏显示并恢复原来尺寸。 ``` - (void)fullScreenAction:(UIButton *)sender { if (self.isFullScreen) { // 恢复竖屏显示并恢复原来尺寸 [UIView animateWithDuration:0.25 animations:^{ self.displayView.transform = CGAffineTransformIdentity; self.displayView.frame = self.view.bounds; }]; self.isFullScreen = NO; [sender setTitle:@"全屏" forState:UIControlStateNormal]; } else { // 横向并全屏显示 CGRect rectInWindow = [self.displayView convertRect:self.displayView.bounds toView:nil]; [UIView animateWithDuration:0.25 animations:^{ self.displayView.transform = CGAffineTransformMakeRotation(M_PI_2); self.displayView.frame = CGRectMake(0, 0, CGRectGetHeight(self.view.bounds), CGRectGetWidth(self.view.bounds)); self.displayView.center = CGPointMake(CGRectGetMidX(self.view.bounds), CGRectGetMidY(self.view.bounds)); }]; self.isFullScreen = YES; [sender setTitle:@"恢复" forState:UIControlStateNormal]; } } ``` 在 fullScreenAction: 方法中,我们通过 CGAffineTransformMakeRotation() 方法来将 displayView 旋转90度,实现横向显示,并将其 frame 设置为横向全屏的尺寸和位置。在恢复竖屏显示时,我们通过 CGAffineTransformIdentity 将其旋转角度恢复为0,并且将其 frame 设置为竖屏的尺寸和位置。同时,我们通过一个布尔类型的变量 isFullScreen 来标记当前状态,以便下一次点击按钮时进行判断。 希望这个回答能够帮到您!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值