uikit

Preferred status bar style of view controller is ignored when in navigation controller

微笑、不失礼 提交于 2019-12-17 23:17:54
问题 I'm writing an iOS App with multiple views. I've set the App to use ViewController-based status bar style, which allows me to use the following code override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent } That worked like expected. But then I've embedded the views in a navigation controller and connected a BarButtonItem with a showSegue. Since then the ViewController of the view switched to ignores the style settings and shows the default black status bar. 回答1: When

Xcode UIView.init(frame:) must be used from main thread only

筅森魡賤 提交于 2019-12-17 23:15:36
问题 I'm trying to render some views in background thread to not affect the main thread. That was never a problem before Xcode 9. DispatchQueue.global(qos: .background).async { let customView = UIView(frame: .zero) DispatchQueue.main.async { self.view.addSubview(customView) } } UIView.init(frame:) must be used from main thread only This error occurs in the second line. Update The Apple UIView Documentation actually says in the Threading Considerations section: Manipulations to your application’s

UIView.animateWithDuration swift loop animation

只愿长相守 提交于 2019-12-17 22:44:23
问题 In ViewController.Swift I managed to make a box animate from one point to another. I thought it would be easy to loop this so the box will animate to one point and then animate back to its original position and then loop again. I have managed to move the object to a position and in "complete" move it back again, but that doesn't make i loop. How can this be achieved? I thought maybe this could work but i honestly don't know: let boxmoves = [CGRect(x: 120, y: 220, width: 100, height: 100),

How do I create a UIView with a transparent circle inside (in swift)?

别来无恙 提交于 2019-12-17 22:07:28
问题 I want to create a view that looks like this: I figure what I need is a uiview with some sort of mask, I can make a mask in the shape of a circle using a UIBezierpath, however I cannot invert this makes so that it masks everything but the circle. I need this to be a mask of a view and not a fill layer because the view that I intend to mask has a UIBlurEffect on it. The end goal is to animate this UIView overtop of my existing views to provide instruction. Please note that I am using swift. Is

How to detect user inactivity since last touch on a particular viewcontroller in iOS?

半城伤御伤魂 提交于 2019-12-17 21:09:03
问题 I need to perform a particular action in a view controller when user don't touch a particular screen for 3 seconds. How can I do that in iOS? 回答1: Override the view's touches began method and reset a timer when you get touches. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self.timer invalidate]; self.timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(inactivityTimerFired) userInfo:nil repeats:NO]; [super touchesBegan:touches withEvent

Thread-safe UIKit methods

会有一股神秘感。 提交于 2019-12-17 21:01:07
问题 I'm trying to find out exactly what methods (names!) became thread safe in UIKit on iOS 4.0. I've searched through Apple's docs with little success. For instance a UIImage created with imageNamed: is not safe to use on other threads (it will occasionally jettison its CGImage from the main thread), while imageWithCGImage might be(?). Also, I've seen claims that UIColor is safe to use on threads other than the main thread. Is there some definite guide as to which methods are safe which ones isn

viewDidLoad is called twice

↘锁芯ラ 提交于 2019-12-17 20:55:01
问题 My viewDidLoad in a view controller is called twice. Once by [UIViewController View] and a second time by [UINib instanciateWithOwner:Options] . Why is this happening? Can it be prevented? 回答1: Any code you put inside of viewDidLoad should be able to run multiple times with out any issues. If you have code that only needs to run once for your controller use -awakeFromNib. The reason is because the view of the view controller can be unloaded and loaded multiple times. The code inside of

How can I solve this Problem with bidirectional dependencies in Objective-C classes?

╄→гoц情女王★ 提交于 2019-12-17 20:54:09
问题 Okay, this might be a very silly beginner question, but: I've got an ClassA, which will create an child object from ClassB and assign that to an instance variable. In detail: ClassA will alloc and init ClassB in the designated initializer, and assign that to the childObject instance variable. It's header looks like this: #import <Foundation/Foundation.h> #import "ClassB.h" @interface ClassA : NSObject { ClassB *childObject; } @end Then, there is the header of ClassB. ClassB has to have a

How come my drawing code keeps resulting in fuzzy shapes?

六眼飞鱼酱① 提交于 2019-12-17 20:42:28
问题 No matter what I do, I can't seem to figure out why my images keep coming out fuzzy on iOS displays. It doesn't matter whether it's one I created in an image editor or drawing code, but I figured that code would make the issue much easier to parse. I know that if the line is 1 pixel wide, it'll appear fuzzy, but I tried multiple line width sizes with similar results. What can I do to make sure my graphics look sharp? UIGraphicsBeginImageContext(CGSizeMake(1000, 1000)); UIBezierPath *bezier =

Keep getting nil from dequeueReusableCellWithIdentifier?

左心房为你撑大大i 提交于 2019-12-17 20:22:12
问题 I've created a prototype cell with identifier "mainViewTableCell" in storyboard file and connected the main table view with a custom controller class named "NTTableViewController". I've implemented function "tableView cellForRowAtIndexPath" in NTTableViewController.m as follows: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString* MAINVIEW_CELLIDENTIFIER = @"mainViewTableCell"; UITableViewCell *newCell = [tableView