Post

Replies

Boosts

Views

Activity

Prevent cell from scrolling out of view
I have a UITableView with multiple screens worth of cells and the height of the cells vary. At a certain point in the user's workflow, I want to prevent a specific cell from being scrolled out of view. I want it to allow it to scroll from the top of the screen to the bottom but not out of view. I'm trying to solve this by updating the tableView.contentInset property with the following logic... let visibleContentHeight = tableView.bounds.height var insetTop = (cell.frame.origin.y - visibleContentHeight) insetTop = (insetTop < 0) ? 0 : -insetTop var insetBottom = tableView.contentSize.height - (cell.frame.origin.y + cell.frame.height + visibleContentHeight) insetBottom = (insetBottom < 0) ? 0 : -insetBottom tableView.contentInset = UIEdgeInsets(top: insetTop, left: 0, bottom: insetBottom, right: 0) This doesn't seem to work exactly right. When scrolling, the cell's top/bottom doesn't line up with the view's top/bottom. And the difference between those margins is not consistent. Printing out some the raw values, it looks like the cell's frame.origin sometimes changes as well as tableView.contentSize.height. I assume the system is using tableView.estimatedRowHeight to calculate the table's content height for the cells that are not loaded, so that's probably another factor. Is setting contentInset not the way to do this? Is there another way? Is there an error in my math/logic? I must be missing something. Any help is appreciated. Thanks.
Topic: UI Frameworks SubTopic: UIKit
1
0
73
Oct ’25
View title misaligned after compiling with Xcode 26
After compiling with Xcode 26, my UIKit view's title appears hugging the screen on the left when run on iOS 16-18 (as shown in the image below). It's fine when run on iOS 26, but not older iOS versions. When I compile the same code with Xcode 16.4, the title aligns with the table rows. Has anyone else seen this? Is this a bug in the frameworks or is there something I could do to resolve?
1
0
107
Sep ’25
Play Audio and Recognize Speech in Car
Hello, I'm trying to determine the best/recommended AVAudioSession configuration (i.e category, mode, and options) for the following use-case. Essentially, I'd like to switch between periods of playing an audio file and then recognizing speech. The audio file is typically speech and I don't intend for playback and speech recognition to occur simultaneously. I'd like for the user to sill be able to interact with Siri and I'd like for it to work with CarPlay where navigation prompts can occur. I would assume the category to use is 'playAndRecord', but I'm not sure if it's better to just set that once for the entire lifecycle, or set to 'playback' for audio file playback and then switch to 'playAndRecord' for speech recognition . I'm also not sure on the best 'mode' and 'options' to set. Any suggestions would be appreciated. Thanks.
0
0
491
Sep ’25