如何将掩码应用于后端视图?
How to apply mask to backend view?
我正在尝试将遮罩应用于后端视图,但无法达到我的期望。我希望视图应该如下图所示。
我尝试以自己的方式实现,但遮罩视图也是从底部出现的。当我们点击 iPad 中的 iCloud 选项时,后端视图立即变为灰色,自定义视图从底部出现。我希望在我的应用程序中需要实现相同的功能。请帮我。提前致谢。
按照以下步骤实现您的要求-
1) 创建一个 BaseView 并在 BaseView 的中心添加一个 CustomView。
2) 将BaseView的背景颜色设置为黑色,不透明度为50%。
3) 将 CustomView 的实际转换保存在一个变量中作为
CGAffineTransform m_actualTransformOfCustomView =
m_customView.transform;
4) 使用
将 CustomView 缩放到较小的 0.01 , 0.01
self.m_customView.transform = CGAffineTransformScale(m_actualTransformOfCustomView, 0.01, 0.01);
4) 使用[UIView amimateWithDuration:]
api 将自定义视图的变换更改为原始的as-
[UIView animateWithDuration:0.5f
delay:0
options:UIViewAnimationOptionCurveEaseOut
animations:^
{
self.m_customView.transform = CGAffineTransformScale(m_actualTransformOfCustomView, 1.0, 1.0);
}
completion:^(BOOL finished)
{
}
];
}
我自己的方法现在可以正常工作了。这是代码片段。享受吧!
-(IBAction)show:(id)sender{
customView = [[UIView alloc] initWithFrame:self.view.frame]; // Mask View
customView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3f];
[self.view addSubview:customView];
// customConfigurationView // PopUp view
CGRect frameCustmVw = customConfigurationView.frame;
frameCustmVw.origin.y = self.view.frame.size.height;
frameCustmVw.origin.x = 134;
customConfigurationView.frame = frameCustmVw;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
frameCustmVw.origin.y = 200;
customConfigurationView.frame = frameCustmVw;
[self.view addSubview:customConfigurationView];
[UIView commitAnimations];
[txtClientID becomeFirstResponder];
}
-(IBAction)remove:(id)sender{
[customView removeFromSuperview]; // Remove mask view
CGRect CustmFrame = customConfigurationView.frame;
CustmFrame.origin.y = 200;//self.view.frame.size.height - customConfigurationView.frame.size.height;
customConfigurationView.frame = CustmFrame;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
CustmFrame.origin.y = self.view.frame.size.height;
customConfigurationView.frame = CustmFrame;
[UIView commitAnimations];
}
我强烈建议你使用这个漂亮整洁的 git 代码
https://github.com/jmascia/KLCPopup
KLCPopup 在使用动画、模糊、淡入淡出等实现模态视图方面确实做得非常好
设置和使用非常简单,简直就是
" 选择你的观点"
"选择你想要的位置"
" 如果你想要一些效果,请添加"
"there you go "
玩得开心 ;)
好的,我关于设置应用程序如何执行此操作的方式的回答很简单......他们只是展示了一个导航控制器,仅此而已,例如
例如创建一个视图控制器子类(我将其命名为 TestViewController
)并在 attribute inspector
中将其大小设置为 freeform
并将其框架的宽度和高度更改为您需要的值并添加视图组件
它将显示宽度和高度为 540*620 的视图控制器以及您的动画
就这些了
- (IBAction)presentAction:(id)sender
{
TestViewController *testVc = [[TestViewController alloc]initWithNibName:@"TestViewController" bundle:nil];
UINavigationController *aNavController = [[UINavigationController alloc] initWithRootViewController:testVc];
aNavController.modalPresentationStyle = UIModalPresentationFormSheet;
aNavController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:aNavController animated:YES completion:nil];
}
我正在尝试将遮罩应用于后端视图,但无法达到我的期望。我希望视图应该如下图所示。 我尝试以自己的方式实现,但遮罩视图也是从底部出现的。当我们点击 iPad 中的 iCloud 选项时,后端视图立即变为灰色,自定义视图从底部出现。我希望在我的应用程序中需要实现相同的功能。请帮我。提前致谢。
按照以下步骤实现您的要求-
1) 创建一个 BaseView 并在 BaseView 的中心添加一个 CustomView。
2) 将BaseView的背景颜色设置为黑色,不透明度为50%。
3) 将 CustomView 的实际转换保存在一个变量中作为
CGAffineTransform m_actualTransformOfCustomView =
m_customView.transform;
4) 使用
将 CustomView 缩放到较小的 0.01 , 0.01self.m_customView.transform = CGAffineTransformScale(m_actualTransformOfCustomView, 0.01, 0.01);
4) 使用[UIView amimateWithDuration:]
api 将自定义视图的变换更改为原始的as-
[UIView animateWithDuration:0.5f
delay:0
options:UIViewAnimationOptionCurveEaseOut
animations:^
{
self.m_customView.transform = CGAffineTransformScale(m_actualTransformOfCustomView, 1.0, 1.0);
}
completion:^(BOOL finished)
{
}
];
}
我自己的方法现在可以正常工作了。这是代码片段。享受吧!
-(IBAction)show:(id)sender{
customView = [[UIView alloc] initWithFrame:self.view.frame]; // Mask View
customView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3f];
[self.view addSubview:customView];
// customConfigurationView // PopUp view
CGRect frameCustmVw = customConfigurationView.frame;
frameCustmVw.origin.y = self.view.frame.size.height;
frameCustmVw.origin.x = 134;
customConfigurationView.frame = frameCustmVw;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
frameCustmVw.origin.y = 200;
customConfigurationView.frame = frameCustmVw;
[self.view addSubview:customConfigurationView];
[UIView commitAnimations];
[txtClientID becomeFirstResponder];
}
-(IBAction)remove:(id)sender{
[customView removeFromSuperview]; // Remove mask view
CGRect CustmFrame = customConfigurationView.frame;
CustmFrame.origin.y = 200;//self.view.frame.size.height - customConfigurationView.frame.size.height;
customConfigurationView.frame = CustmFrame;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
CustmFrame.origin.y = self.view.frame.size.height;
customConfigurationView.frame = CustmFrame;
[UIView commitAnimations];
}
我强烈建议你使用这个漂亮整洁的 git 代码
https://github.com/jmascia/KLCPopup
KLCPopup 在使用动画、模糊、淡入淡出等实现模态视图方面确实做得非常好
设置和使用非常简单,简直就是
" 选择你的观点"
"选择你想要的位置"
" 如果你想要一些效果,请添加"
"there you go "
玩得开心 ;)
好的,我关于设置应用程序如何执行此操作的方式的回答很简单......他们只是展示了一个导航控制器,仅此而已,例如
例如创建一个视图控制器子类(我将其命名为 TestViewController
)并在 attribute inspector
中将其大小设置为 freeform
并将其框架的宽度和高度更改为您需要的值并添加视图组件
它将显示宽度和高度为 540*620 的视图控制器以及您的动画
就这些了
- (IBAction)presentAction:(id)sender
{
TestViewController *testVc = [[TestViewController alloc]initWithNibName:@"TestViewController" bundle:nil];
UINavigationController *aNavController = [[UINavigationController alloc] initWithRootViewController:testVc];
aNavController.modalPresentationStyle = UIModalPresentationFormSheet;
aNavController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:aNavController animated:YES completion:nil];
}