answerstu

Cocoa: Why assigning a frame to a frame doesn´t work but assigning bounds does

I´ve been reading the different questions ( Cocoa: What's the difference between the frame and the bounds?, UIView frame, bounds and center) related to the difference between frame and bounds but still I don´t understand why when something like this:UILabel *newMark = [[UILabel alloc] initWithFrame:self.frame];newMark.text = @"|A3";[self addSubview:newMark];or this:UILabel *newMark = [[UILabel alloc] init];newMark.text = @"|A3";newMark.frame = self.frame;[self addSubview:newMark];The label is not displayed, but when doing the equivalent wit...Read more

cocoa touch - Subclassing SKShapeNode with Swift

I'm trying to subclass SKShapeNode with Swift. So far I've got something like this:import UIKitimport SpriteKitclass STGridNode: SKShapeNode { init() { super.init() self.name = "STGridNode" self.fillColor = UIColor(red: 0.11, green: 0.82, blue: 0.69, alpha: 1) }}In my code I want so do something along the lines of:let s = STGridNode(rectOfSize: CGSize(width: 100, height: 100))So my question is - how do I implement rectOfSize in the initialiser for STGridNode? I've tried:init(rectOfSize: CGPoint) { super.init(rectOf...Read more

cocoa touch - What is the most robust way to force a UIView to redraw?

I have a UITableView with a list of items. Selecting an item pushes a viewController that then proceeds to do the following. from method viewDidLoad I fire off a URLRequest for data that is required by on of my subviews - a UIView subclass with drawRect overridden. When the data arrives from the cloud I start building my view hierarchy. the subclass in question gets passed the data and it's drawRect method now has everything it needs to render.But.Because I don't call drawRect explicitly - Cocoa-Touch handles that - I have no way of informing C...Read more

cocoa touch - iOS 9 crash when presenting UIActivityViewController : [UIView _fromWindowOrientation] unrecognized selector sent to instance (UIView)

My app is crashing any time I present a UIActivityViewController, only on iOS9.I've isolated the code down to this: (Cleared everything from the AppDelegate minus setting my test view controller as the root and only VC).In the test view controller on button tap:(I made the activityVC an instance property to check if there was a deallocation issue because other debugging efforts suggested that the activityVC might get dealloced during presentation)NSString *string = @"PLS WORK";self.activityViewController =[[UIActivityViewController alloc] initW...Read more

cocoa touch - Page transition animation between views

I'm fairly new to iOS, and I'm experimenting with switching views. I have 2 views, each with a button to switch the page. So far I've only managed to use UIViewTransitionAnimation but it only has the Flip and Curl Animations.Instead of flips and curls, I'm trying to make the pages slide between views either right to left or vice versa. I've been searching on google, forums and even the developer.apple.com about transitioning between pages but I still couldn't find what I'm looking for. I did find this CATransition class but there's just not eno...Read more

cocoa touch - iPhone's UITableViewCellAccessoryCheckMark

I have an issue in creating a CheckMarkAccessoryView in the UITableView.When i select a row in the table i can get a checked mark for that row,but randomly some other rows in the table also gets the check mark.I want only that cell to get the check mark.How can i do this?I am coding for an exclusive list.The following is the code which i have used.-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1;}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if(tableView==tableVi...Read more

cocoa touch - iOS7 UIWebView - Set content starting position below navigation bar

I have a UIViewController designed in a Storyboard (IB) as follows :UIWebView stretched to fill the entire canvasUIWebView has AutoLayout constraints to pin all 4 sides to the edges of the superviewUIViewController has all 'Extend Edges' options ticked so UIWebView sits underneath navigation barUIViewController has 'Adjust Scroll View Insets' untickedUIViewController is loaded within a UINavigationControllerWhat I want to happen when the VC loads is for the top of the UIWebView content to be positioned immediately below the navigation bar, and ...Read more

cocoa touch - Is it wise to "nest" UIViewControllers inside other UIViewControllers like you would UIViews?

I've got a fairly complex view, for me anyway, that has a few "trays" with custom interface items on them. They slide in and out of my root view. I'd like to nest (addSubview) the items inside the view. Each needs some setup before being displayed...and none can be configured in IB (they're subclasses of UIView). I'm wondering if it makes sense to subclass UIViewController for each "tray" and then have the VC's view property point to the "tray" view which I can populate with my custom UIView objects. This way I can leverage the viewDidLoad, etc...Read more

cocoa touch - CNContactPickerViewController content bleeds to search bar and status bar

I'm presenting CNContactPickerViewController (strongly referenced ivar):contactsViewController = [[CNContactPickerViewController alloc] init];contactsViewController.delegate = self;[self presentViewController:contactsViewController animated:YES completion:nil];However, here is the result:After encountering the problem I've tried changing the appearance of search bar (not sure what I should set, just trying): [[UISearchBar appearanceWhenContainedInInstancesOfClasses:@[[CNContactPickerViewController class]]] setBarTintColor:[UIColor redColor]]; b...Read more

cocoa touch - Make SearchBar higher in navigation bar

I tried to create a search bar and it's working ok now, but I can't figured out how to make it a little bit higher, right under the status bar.Search bar is created programmatically, I used this code:let searchController = UISearchController(searchResultsController: nil)override func viewDidLoad() { super.viewDidLoad() searchController.searchResultsUpdater = self searchController.obscuresBackgroundDuringPresentation = false searchController.hidesNavigationBarDuringPresentation = false definesPresentationContext = true navigati...Read more

cocoa touch - How can I scale at an anchor point using CGAffineTransform?

Edited to better explain my problemI am trying to perform a zoom operation using my custom view (not UIView). The view has translation, scale, rotate values. I use these as follows, between calls to glPushMatrix() and glPopMatrix().- (void)transform{ glTranslatef(translation.x + anchor.x, translation.y + anchor.y, 0.0f); //glRotatef(-rotation * 57.2957795f, 0.0f, 0.0f, 1.0f); glScalef(scale.x, scale.y, 1.0f); glTranslatef(-anchor.x, -anchor.y, 0.0f);}I am trying to figure out how I should modify the anchor and/or translation values ...Read more

cocoa touch - Get a user-readable version of the class name in swift (in objc NSStringFromClass was fine)

Is there an equivalent of NSStringFromClass in Swift that gives a user-readable version of the class name? I've tried to use it with a native Swift class I created, but as you can see, the result seems to be the compiler's internal representation of the class name:println(NSStringFromClass(MyClass.self))Result:_TtC5test7MyClassI've tried adding the @objc attribute to the class, and making it a subclass of NSObject, but it makes no difference. I've discovered that if I replace MyClass with an Objective-C class of the same name, and import this i...Read more