小编hua*_*nyu的帖子

Assets.xcassets和images.xcassets有什么区别?

当我新建一个xcode项目时,有一个由defalut创建的图像文件夹,我想知道它们之间有什么区别?Assets.xcassets是否更新?

xcode image project ios

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

NSTimer自我弱; 为什么没有叫dealloc?

考虑具有强(或弱,相同)NSTimer属性的视图控制器:

__weak __typeof(self) ws = self;
self.timer = [NSTimer scheduledTimerWithTimeInterval:2 target:ws selector:@selector(timerTigger:) userInfo:nil repeats:YES];
Run Code Online (Sandbox Code Playgroud)

但是为什么这个视图控制器不会调用dealloc方法,无论是传递strong还是weak引用self

这是详细的代码:

#import "SecondViewController.h"

@interface SecondViewController ()

@property (nonatomic, weak) NSTimer *timer;

@end

@implementation SecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    __weak __typeof(self) ws = self;
    self.timer = [NSTimer scheduledTimerWithTimeInterval:2 target:ws selector:@selector(timerTigger:) userInfo:nil repeats:YES];

}

- (void)timerTigger:(id)timer {
    NSLog(@"do someting");
}

- (void)dealloc {
    NSLog(@"SecondViewController dealloc");
}
Run Code Online (Sandbox Code Playgroud)

objective-c nstimer dealloc ios

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

UIView中的childViewController.view.frame呈现不同的值

我使用childViewController在项目中分离视图,但是发生了一些奇怪的问题,这是我的代码。

class ViewController: UIViewController {

    var container = UIView()
    var childVC = ChildViewController()

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .white

        addChildViewController(childVC)
        childVC.didMove(toParentViewController: self)

        addChildView()

        setContainerFrame()
    }

    func setContainerFrame() {
        container.frame = CGRect(x: 0, y: 100, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height - 100)
        container.backgroundColor = .red
        view.addSubview(container)
    }

    func addChildView() {
        let frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
        childVC.view.frame = frame
        childVC.view.backgroundColor = .green
        container.addSubview(childVC.view)
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        print("childVC.view.frame: \(childVC.view.frame)")
    }
} …
Run Code Online (Sandbox Code Playgroud)

frame ios childviewcontroller swift

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