我将在Swift中重载init方法如何实现它?
这里我的代码不起作用
代码删除
编辑:
所以它会很好
override init() {
super.init();
}
init(title:String?) {
super.init();
self.title = title
}
convenience init(title:String?, imageName:String?) {
self.init(title:title)
self.imageName = imageName
}
convenience init(title:String?, imageName:String?, contentKey:String?) {
self.init(title:title, imageName:imageName)
self.contentKey = contentKey
}
Run Code Online (Sandbox Code Playgroud) 嗨我想在视图中添加一个CALayer Shadow,其中阴影位于视图右侧,最简单的方法是:
someView.layer.shadowColor = [[UIColor blackColor] CGColor];
someView.layer.shadowOffset = CGSizeMake(0.0f,0.0f);
someView.layer.shadowOpacity = 1.0f;
someView.layer.shadowRadius = 10.0f;
someView.layer.shadowPath = [[UIBezierPath bezierPathWithRect:someView.bounds] CGPath];
Run Code Online (Sandbox Code Playgroud)
但是当我增加shadowRadius它看起来不太好时,我会添加一个更大的阴影就像一个阴影.我如何制作一个左右看起来很好的阴影.
嗨我有一个问题,在iOS8中旋转Modal呈现的ViewController.这一切在iOS7及更低版本上运行良好.
应用结构:
我的问题是当我提出模态控制器时旋转设备时,模态控制器的视图没有调整到景观框架.
看起来像这样:
调用了旋转方法,当我手动将视图的框架设置为横向时,右侧(屏幕灰色侧)的用户交互不起作用.
RootController代码:
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
- (NSUInteger) supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)
模态控制器代码:
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration
{
if (self.presentingViewController != nil) {
[self.presentingViewController willAnimateRotationToInterfaceOrientation:toInterfaceOrientation
duration:duration];
}
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration
{
if (self.presentingViewController != nil) {
[self.presentingViewController willRotateToInterfaceOrientation:toInterfaceOrientation
duration:duration];
}
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
if (self.presentingViewController != nil) {
[self.presentingViewController didRotateFromInterfaceOrientation:fromInterfaceOrientation];
}
}
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
} …
Run Code Online (Sandbox Code Playgroud) 你好,我有一个自动布局问题UIScrollView
和ModalViewController
.以下是我的编码步骤作为示例代码:
1)我有UIViewController
一个UIScrollView
assubView
UIViewController *viewController = [[UIViewController alloc] init];
UIScrollView *scrollView = [[UIScrollView alloc] init];
scrollView.translatesAutoresizingMaskIntoConstraints = NO;
[viewController.view addSubview:scrollView];
UIView *superView = viewController.view;
NSDictionary *viewsDict = NSDictionaryOfVariableBindings(superView,scrollView);
[superView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[scrollView(==superView)]|"
options:0
metrics:nil
views:viewsDict]];
[superView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[scrollView(==superView)]|"
options:0
metrics:nil
views:viewsDict]];
Run Code Online (Sandbox Code Playgroud)
这很有效
2)我添加2个子视图 scrollView
UIView *view1 = [[UIView alloc] init];
view1.backgroundColor = [UIColor redColor];
view1.translatesAutoresizingMaskIntoConstraints = NO;
[scrollView addSubview:view1];
UIView *view2 = [[UIView alloc] init];
view2.backgroundColor = [UIColor greenColor];
view2.translatesAutoresizingMaskIntoConstraints = NO;
[scrollView …
Run Code Online (Sandbox Code Playgroud) ios ×3
iphone ×2
autolayout ×1
calayer ×1
init ×1
ios8 ×1
objective-c ×1
overloading ×1
rotation ×1
shadow ×1
swift ×1
uiscrollview ×1
xcode ×1