I've been trying to implement an overlaying activity indicator for a UITableView by this tutorial - http://www.markbetz.net/2010/09/30/ios-diary-showing-an-activity-spinner-over-a-uitableview/
It might be a little old but it seems to work well apart from a little issue with the bounds to display the overlay in.
I try to get those bounds here:
-(void)showActivityView {
if (overlayController == nil) {
// This is where I get the wrong bounds
overlayController = [[ActivityOverlayController alloc] initWithFrame:self.tableView.bounds];
}
[self.tableView insertSubview:overlayController.view aboveSubview:self.tableView];
}
And this gets the bounds and displays my overlay perfectly if I call the method AFTER the table is loaded and filled but if I call it before it gets wrong bounds. I've tried getting the bounds of the tableView.superView but this just displays the overlay in the top left corner.
I understand this is because the UITableView doesn't contain any cells before loading and so doesn't have proper bounds yet but I don't know of a way to get these.
Wrong display:
Correct (but after loading table) display:
How about using the UITableView's "frame" property, rather than "bounds"? If the Table View is defined in a XIB, the frame should already be fine before loading cells into the table. So you would need to replace:
overlayController = [[ActivityOverlayController alloc] initWithFrame:self.tableView.bounds];
with:
overlayController = [[ActivityOverlayController alloc] initWithFrame:self.tableView.frame];
According to the example link you should do
-(void)showActivityView {
if (overlayController == nil) {
// This is where I get the wrong bounds
overlayController = [[ActivityOverlayController alloc] initWithFrame:self.tableView.superview.bounds];
}
[self.tableView.superview insertSubview:overlayController.view aboveSubview:self.tableView];
}
Why are you doing [self.tableView insertSubview:..] instead of [self.tableView.superview insertSubview:..]?
Related
The search bar is appearing exactly 64 points too low:
All of the other frames are exactly correct.
Edit:
- It's the UISearchController's view that is getting the wrong origin.y. It gets set to 64, when it should be 0.
If I add this method:
- (void)didPresentSearchController:(UISearchController *)searchController
{
[super didPresentSearchController:searchController];
searchController.view.frame = CGRectMake(0, 0, searchController.view.frame.size.width, searchController.view.frame.size.height);
}
Then the views align. However, its janky because it jumps. If I modify the frame in willPresentSearchController it does not work, as the controller must be doing some sort of layout after its presented.
If I use SparkInspector, and edit the frame of the UISearchBarContainerView from origin 64 (what it gets set at, to 0), the problem is resolved.
Here is my relevant configuration:
self.searchResultsController = [[GMSearchTableViewController alloc] init];
self.definesPresentationContext = YES;
self.searchController = [[UISearchController alloc] initWithSearchResultsController:self.searchResultsController];
self.searchController.dimsBackgroundDuringPresentation = YES;
self.searchController.hidesNavigationBarDuringPresentation = NO;
self.searchController.searchBar.frame = CGRectMake(0, 0, self.view.frame.size.width, 44);
[self.view addSubview:self.searchController.searchBar];
I'm not using Interface Builder, everything is configured in code.
I'm positive that setting definesPresentationContext is correct.
The VC sits in a regular UINavigationController, which is inside a SplitViewController (but problem exists on iPhone as well).
I feel like I'm missing a simple configuration option in regards to the UINavigationBar
I also have a different controller that uses a custom Container View Controller model, which is more complex, and that one works.
When I set
self.definesPresentationContext = NO;
This happens:
So now the UISearchBar gets positioned correctly, but the presentation context is wrong, causing the UISearchController's table view to occupy the full view.
Well in classic fashion, I've found a solution (https://stackoverflow.com/a/30010473/579217)
This does the trick:
- (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar
{
if (bar == self.searchController.searchBar) {
return UIBarPositionTopAttached;
}
else { // Handle other cases
return UIBarPositionAny;
}
}
If your tableView is custom UItableView and not a UItableViewController you should hide top of the tableview under navigation bar, because search bar automatically attached on header of table view and if your table view starts under navigation bar i cause this problem. Just make the table view full screen from top of navigation bar.
Im loading local html files, since iOS7 there is added white space on top in the UIWebView.(I cant post an image as i do not have enough points.)
image can be seen here- snap shot from iPhone simulator, uiwebview surrounded by black frame, the html content is grey, but there is white added above it
I have tried to adjust the zoom using
[webView stringByEvaluatingJavaScriptFromString:#"document. body.style.zoom = 5.0;"];
webView.scalesPageToFit = NO;
credit to: Srikar Appal
I also set tried to remove white spacing:
NSString *padding = #"document.body.style.margin='0';document.body.style.padding = '0'";
[webView stringByEvaluatingJavaScriptFromString:padding];
credit to: thenextmillionaire
still no luck. In the desktop chrome browser there is no whitespace. The html files are Google Swiffy files - containing html and JSON.
edit: updated Image
Try self.automaticallyAdjustsScrollViewInsets = NO; in ViewDidLoad.
ios 7 add 64px automatically for scroll view. (status bar and nav bar)
This problem only affects the UIWebView if it is the first subview of the parent view. One alternative way to work around this problem is to add another non-visible empty view to the parent view as the first view. In Interface Builder add a zero size subview and use the Editor->Arrange->Send to Back menu command.
If you're not using Interface Builder, but instead are subclassing the UIWebView, then it can be done by creating a UIView instance variable called scrollFixView and overriding the following methods:
- (void)didMoveToSuperview
{
[super didMoveToSuperview];
if ([self superview].subviews.firstObject == self) {
_scrollFixView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
_scrollFixView.hidden = YES;
[[self superview] insertSubview:_scrollFixView belowSubview:self];
}
}
- (void)removeFromSuperview
{
if (_scrollFixView) {
[_scrollFixView removeFromSuperview];
_scrollFixView = nil;
}
[super removeFromSuperview];
}
I had the same problem so I tried a few things:-)
This worked for me, but correct me please if there is a better way.
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
if(self.navigationController.navigationBar.translucent == YES)
{
_webView.scrollView.contentOffset = CGPointMake(_webView.frame.origin.x, _webView.frame.origin.y - 54);
}
}
So basically you need to :
1) Add the UIWebView delegate method - webViewDidFinishLoad:
2) Then I setup an if statement to check if the translucent option is active.
The last one you only need to do of course if you give the user the option within your app.
The number after the _webView.frame.origin.y is just for my app. It may differ for you.
I solved this problem by simply setting a constraint on the WebView, setting the top space between it and the View top to 0, causing the NavBar to overlap the whitespace.
One alternative to Jeff Kranenburg's method is to subclass and override the UIWebView subclasses' UIScrollViewDelegate method scrollViewDidScroll:. This is only appropriate if scrolling is turned off for your subclass.
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if ([[self superclass] instancesRespondToSelector:_cmd]) {
[super scrollViewDidScroll:scrollView];
}
[self fixUpScrollViewContentOffset];
}
- (void)fixUpScrollViewContentOffset
{
if (!CGPointEqualToPoint(self.scrollView.contentOffset, CGPointZero)) {
self.scrollView.contentOffset = CGPointZero;
}
}
I already got it .
here my logic code, When the application open the website you must get the size of your webview then set it on height
here my code
ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) webpage.getLayoutParams();
p.height = webpage.getHeight();
// check if how long you need to set your height for webpage then set it :)
Log.e(" webpage.getHeight()", String.valueOf(webpage.getHeight()));
webpage.setLayoutParams(p);
Hope you will take my code and my answer to :) works on any devices even tabs too :)
I'm using iCarousel to display editable question cards. The cards contain a UITextView for entering the question (or already contain text as you swipe through filled cards). However, when the carousel is presented and scrolled, sometimes text views appear empty.
This is due to a UITextView optimization of not drawing text offscreen. But text views in a UITableView will not suffer from this.
As many know, using setNeedsDisplay will NOT work due to the optimization, so it doesn't redraw the text.
I currently change the text view's frame by adding and then removing 1px. This forces a redraw. However, I can only do this when the item changes. iCarousel does not have a willDisplayCell delegate method. (Nick, can you add one easily? The code baffles me)
Because iCarousel is preloading many views for smoothness (which is necessary, setting iCarouselOptionVisibleItems doesn't fix anything) there doesn't seem to be anything else I can do but know when the view is about to come on screen. Suggestions?
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
MIQuestionView *questionView = (MIQuestionView *)view;
if (questionView == nil)
{
MIQuestionType type = [self.testSection.questionType integerValue];
questionView = [[MIQuestionView alloc] initWithFrame:CGRectNull questionType:type];
questionView.delegate = self;
}
questionView.question = [self.testSection.questions objectAtIndex:index];
return questionView;
}
The text view is embedded in the MIQuestionView. The text is set in the question setter. There's no way for me to know when it's coming onto the screen. To be clear, I don't want to resize. The text is not drawn offscreen and appear blank when coming on-screen.
Sorry, I didn't look for ambiguous code above:
- (id)initWithFrame:(CGRect)frame questionType:(MIQuestionType)type
{
if (CGRectEqualToRect(frame, CGRectNull))
frame = CGRectMake(0, 0, 650, 244);
self = [super initWithFrame:frame];
...
It's an odd bug. I'm not sure if it's an issue with iCarousel or just a quirk of iOS that you need to deal with when dynamically adding and removing UITextViews from the view hierarchy.
I have a solution that's maybe a bit cleaner than the ones you've found though; Just add this to your MICardView:
- (void)didMoveToSuperview
{
if (self.superview)
{
_textView.frame = self.bounds;
}
}
This basically forces the textView to re-layout every time the cardView is recycled, and it avoids you having to do anything special in your view controller to work around the issue.
I have no idea why this code isn't working, but hopefully the fix is simple, I hope someone can help.
I have 2 functions, enterFullScreen and exitFullScreen.
In the enterFullScreen method, I set an NSView's frame to the Window's frame, which has a full-screen effect, this is what I want. Within this method I store the old frames so that in the exitFullScreen method I can set them back, but this isn't working. It has no effect whatsoever. The code is as follows:
NSView oldView, oldViewContainer;
- (void) enterFullScreen:(NSView*)newView
{
// Store original views
oldView = newView;
oldViewContainer = _newViewContainer;
// Set new views to fit window
[_newViewContainer setFrame:[_window.contentView frame]];
[newView setFrame:[_window.contentView frame]];
}
- (void) exitFullScreen:(NSView*)newView
{
// Restore old views
[_newViewContainer setFrame:[oldViewContainer frame]];
[newView setFrame:[oldView frame]];
}
The enter fullscreen method works exactly as expected, but for some reason I can't set the 2 Views back to their original size/location.
I don't know if it's because I can't just store the whole view, or if the origin is causing problems?
I've tried every combination, if somebody could help I'd be really grateful.
Thanks in advance.
You don't want to set oldView to newView, that makes them the same view, so when you resize newView to full screen, oldView's frame also is set to full screen. You want to save the old frame, not the view, so:
oldFrame = newView.frame; (to store the original frame)
then when you resize smaller,
[newView setFrame:oldFrame];
I'm writing a dynamic wizard application using cocoa/objective c on osx 10.6. The application sequences through a series of views gathering user input along the way. Each view that is displayed is provided by a loadable bundle. When the app starts up, a set of bundles are loaded and as the controller sequences through them, it asks each bundle for its view to display. I use the following to animate the transition between views
[[myContentView animator] replaceSubview:[oldView retain] with:newView];
This works fine most of the time. Every once in a while, a view is displayed and some of the subviews are not displayed. It may be a static text field, a checkbox, or even the entire set of subviews. If, for example, a checkbox is not displayed, I can still click where it should be and it then gets displayed.
I thought it might have something to do with the animation so I tried it like this
[myContentView replaceSubview:[oldView retain] with:newView];
with the same result. Any ideas on what's going on here? Thanks for any assistance.
I don't think is good to use this [oldView retain]. This retain do not make sense. The function replaceSubview will retain it if it is necessary.
Because it work "most of the time" I think it is a memory problem. You try to use a released thing. Test without it and see what happens.
I got the same problem, replaceSubview didn't work.
Finally i found something wrong with my code. so here are the rules :
Both subviews should be in MyContentview's subviews array.
OldView should be the topmost subview on MyContentView or replacesubview will not take place.
here is a simple function to perform replacesubview
- (void) replaceSubView:(NSView *)parentView:(NSView *)oldView:(NSView *)newView {
//Make sure every input pointer is not nill and oldView != newView
if (parentView && oldView && newView && oldView!=newView) {
//if newview is not present in parentview's subview array
//then add it to parentview's subview
if ([[parentView subviews] indexOfObject:newView] == NSNotFound) {
[parentView addSubview:newView];
}
//Note : Sometimes you should make sure that the oldview is the top
//subview in parentview. If not then the view won't change.
//you should change oldview with the top most view on parentview
//replace sub view here
[parentView replaceSubview:oldView with:newView];
}
}