小编Zer*_*ter的帖子

Swift Overload init()

我将在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)

xcode overloading init swift

9
推荐指数
1
解决办法
2万
查看次数

UIView的左右阴影

嗨我想在视图中添加一个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它看起来不太好时,我会添加一个更大的阴影就像一个阴影.我如何制作一个左右看起来很好的阴影.

iphone shadow calayer ios

6
推荐指数
2
解决办法
2万
查看次数

iOS8 Modal ViewController轮换问题

嗨我有一个问题,在iOS8中旋转Modal呈现的ViewController.这一切在iOS7及更低版本上运行良好.

应用结构:

  • RootController(支持的Orientation:Portrait)
  • Modal提供的ViewController(支持的Orientation:All)

我的问题是当我提出模态控制器时旋转设备时,模态控制器的视图没有调整到景观框架.

看起来像这样:

在此输入图像描述 调用了旋转方法,当我手动将视图的框架设置为横向时,右侧(屏幕灰色侧)的用户交互不起作用.

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)

objective-c rotation ios ios8

6
推荐指数
1
解决办法
973
查看次数

ScrollView的iOS AutoLayout问题

你好,我有一个自动布局问题UIScrollViewModalViewController.以下是我的编码步骤作为示例代码:

1)我有UIViewController一个UIScrollViewassubView

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)

iphone uiscrollview modalviewcontroller ios autolayout

2
推荐指数
1
解决办法
6496
查看次数