How to slide a UIView right above a UITabBar - iphone

I have a UIView that I want to slide from behind a UITabBar to be position right on top of it.
This doesn't work. My view does not appear.
- (void)showNotificationBar
{
CGRect frame = CGRectMake(0, 500, 320, 32);
frame.origin.y = CGRectGetMaxY(self.parentViewController.tabBarController.tabBar.frame) - frame.size.height;
notificationBar.frame = frame;
[self.parentViewController.tabBarController.tabBar.superview insertSubview:notificationBar
belowSubview:self.parentViewController.tabBarController.tabBar];
[UIView animateWithDuration:0.5 animations:^{
CGRect frame = notificationBar.frame;
frame.origin.y = CGRectGetMaxY(self.parentViewController.tabBarController.tabBar.frame);
notificationBar.frame = frame;
}];
}

Initialize frame.origin.y like this:
frame.origin.y = self.tabBarController.tabBar.frame.origin.y;
In the animations block, set it like this:
frame.origin.y -= frame.size.height;

If you want it to show in every view, you could do to things: either show it at the bottom of every view or show it in the application's window. I personally like this second approach better because it helps avoiding duplicate code:
CGFloat notificationBarHeight = 40.0f;
UIView *notificationBar = [[UILabel alloc]initWithFrame:CGRectMake(0, self.tabBarController.tabBar.frame.origin.y - notificationBarHeight, 320, notificationBarHeight)];
[self.window insertSubview:notificationBar atIndex:[[self.window subviews]count]];

[self.view insertSubview:notificationView atIndex:1]; worked for me...

Related

CGRectOffset Causes Swiping The Wrong Way

Trying to be able to swipe away a cell and another view will show up. This is my code so far, but I am unable to see the rightView. Instead it limits me to seeing the leftView(I want the opposite...leftView does not even exist). Very confused with CGRects and CGRectOffsets. If you could correct my code that would be great. Thanks.
- (void)layoutSubviews
{
[super layoutSubviews];
CGRect frame = self.bounds;
self.scrollView.frame = frame;
self.scrollView.contentSize = CGSizeMake(frame.size.width*2, frame.size.height);
self.centerView.frame = CGRectOffset(frame, frame.size.width, 0);
self.rightView.frame = CGRectOffset(frame, frame.size.width*2, 0);
[self.scrollView scrollRectToVisible:self.centerView.frame animated:NO];
[self.scrollView setUserInteractionEnabled:YES];
self.scrollView.scrollEnabled = YES;
}
You are setting the centerView and rightView's offset to be frame.size.width and frame.size.width*2 respectively. What you want is for the center to be 0 and the right view to be frame.size.width.
You are just moving your views over too much so the left frame.size.width number of pixels just dont have a view.

How to add an animation in adding a view?

I have an application in which I had a button on the navigationbar.
When clicking on that I need to add a subview to the self.view.
DemoViewController *demoViewController1 = [[DemoViewController alloc] initWithNibName:#"DemoViewController" bundle:nil];
CGRect frame=demoViewController1.view.frame;
frame.origin.y = -300;
[self.view addSubview:demoViewController1.view];
[UIView animateWithDuration:0.5
animations:^{
CGRect frame1 = frame;
frame1.origin.y = 0;
demoViewController1.view.frame = frame1;
}];
I was tried by setting the frame origin y of the adding view(it is of another view controller).to some negetive value and by clicking bring it to 0.but it doesnt have that drop down effect.
I need to add the view with an animation like drop down view. and when pressed again on the button need to remove also like this.
Can anybody help me on this?
You add the view as subview with a frame that is not on the screen (e.g. negative y coordinate) and modify the frame animated:
MyView *myView = [[MyView alloc] initWithFrame:CGRectMake(50, -200, 200, 200)];
[self.view addSubview:myView];
[UIView animateWithDuration:0.3
animations:^{
CGRect frame = myView.frame;
frame.origin.y = 0;
myView.frame = frame;
}];
And the code for removal:
[UIView animateWithDuration:0.3
animations:^{
CGRect frame = myView.frame;
frame.origin.y = -1 * frame.size.height;
myView.frame = frame;
}
completion:^(BOOL finished) {
[myView removeFromSuperview];
}];
Edit:
Replace your code with this:
DemoViewController *demoViewController1 = [[DemoViewController alloc] initWithNibName:#"DemoViewController" bundle:nil];
CGRect frame=demoViewController1.view.frame;
frame.origin.y = -300;
demoViewController1.view.frame = frame; // You forgot this line
[self.view addSubview:demoViewController1.view];
[UIView animateWithDuration:0.5
animations:^{
CGRect frame1 = demoViewController1.view.frame;
frame1.origin.y = 0;
demoViewController1.view.frame = frame1;
}];
First keep ur view at bottom.
when it's clicked first time
do this
[UIView animateWithDuration:0.3 animations:^{
//keep points that's in a screen
self.view.center = CGPointMake(x,y,width,height);
}];
when it's clicked second time
give points below the visible screen
[UIView animateWithDuration:0.3 animations:^{
//keep points that's in a screen
self.view.center = CGPointMake(x,y,width,height);
}];
Let me know if you find a better way than this.
[self.yourView setFrame:setYourInitialFrame];
[UIView animateWithDuration: 1.00 animations:^{
[self.yourView setFrame:setYourFinalFrame];
}];

Dynamic UITextView in a dynamic UIScrollView - iOS

I'm facing a problem which takes me too long to solve.
I built a view, which contains a ScrollView. in the ScrollView, there's a view, which contains an image, and a UITextView. the textview should be in a dynamic height, with scrolling disabled. the textview gets all the text, but cut it off, and shows only the text that fits the height. in addition, the ScrollView doesn't changes.
- (void)viewDidLoad
....
//sets the text to the textview
[self.contentArticle setText:[NSString stringWithString:xmlParser.articleContent]];
//configures the scrollView
[self configureScrollView];
....
- (void)configureScrollView {
[self.contentView addSubview:self.contentArticle];
[self.scrollView addSubview:self.contentView];
CGRect frame = self.contentView.frame;
frame.size.height = self.contentArticle.contentSize.height;
self.scrollView.frame = frame;
[self.contentView sizeToFit];
[self.scrollView sizeToFit];
self.scrollView.contentSize = self.contentView.frame.size;
self.contentArticle.editable=NO;
self.contentArticle.scrollEnabled=NO;
//enable zoomIn
self.scrollView.delegate=self;
self.scrollView.minimumZoomScale=1;
self.scrollView.maximumZoomScale=7;
I did so many changes, and im not sure what is going on in there anymore!...
help would be sooo nice :)
UPDATE-
- (void)configureScrollView {
[self.contentView addSubview:self.contentArticle];
[self.scrollView addSubview:self.contentView];
CGRect textViewFrame = self.contentArticle.frame;
textViewFrame.size = [self.contentArticle contentSize];
self.contentArticle.frame = textViewFrame;
[self.scrollView setContentSize:textViewFrame.size];
self.contentArticle.editable=NO;
self.contentArticle.scrollEnabled=NO;
}
Try
- (void)configureScrollView{
self.contentView.autoresizingMask = UIViewAutoresizingNone;
self.contentArticle.autoresizingMask = UIViewAutoresizingNone;
CGRect textViewFrame = self.contentArticle.frame;
textViewFrame.size = [self.contentArticle contentSize];
self.contentArticle.frame = textViewFrame;
CGRect contentViewFrame = self.contentView.frame;
contentViewFrame.size.height = textViewFrame.origin.y+textViewFrame.size.height;
self.contentView.frame = contentViewFrame;
[self.scrollView setContentSize:contentViewFrame.size];
self.contentArticle.editable=NO;
self.contentArticle.scrollEnabled=NO;
//enable zoomIn
self.scrollView.delegate=self;
self.scrollView.minimumZoomScale=1;
self.scrollView.maximumZoomScale=7;
}
Source code
had same issue , tried to find solution for many days and finally i got it working.
I have a textview inside a scrollview.
disabled autolayout from storyboards
ive added the textview to scrollview with addsubview
and finally set the content of the scrollview, to the textview frame height.
Below my code:
_textView.text = stripped; //(some string ,yours: contentArticle)
[_textView sizeToFit];
CGRect frame = _textView.frame;
frame.size.height = _textView.contentSize.height;
_textView.scrollEnabled = NO;
_textView.frame = frame;
[self.scrollView addSubview:_textView];
[self.scrollView setContentSize:CGSizeMake(320,frame.size.height)];
Hope it helps!
You need to set self.contentView height first Use this code:
- (void)configureScrollView {
[self.contentView addSubview:self.contentArticle];
CGRect frame = self.contentArticle.frame;
frame.size.height = self.contentArticle.contentSize.height;
self.contentArticle.frame = frame;
[self.scrollView addSubview:self.contentView];
frame = self.contentView.frame;
frame.size.height += self.contentArticle.frame.height;
self.contentView.frame = frame;
self.scrollView.contentSize = self.contentView.frame.size;
self.contentArticle.editable=NO;
self.contentArticle.scrollEnabled=NO;
//enable zoomIn
self.scrollView.delegate=self;
self.scrollView.minimumZoomScale=1;
self.scrollView.maximumZoomScale=7;
}

Customize Scrolling indicator

Is there a way to customize scrolling indicator(vertical or horizontal) in UIScrollView. For example, change it's color or position in scrollview.
First, you have to uncheck showVerticalIndicator and showHorizontallIndicator in the Interface Builder.
Then in the viewDidLoad method add :
[super viewDidLoad];
self.scrollViewBarImgView = [[UIImageView alloc] init];
UIImage *imgBar = [UIImage imageNamed:#"scroller.png"];
[self.scrollViewBarImgView setImage:imgBar];
CGRect frame = scrollViewBarImgView.frame;
frame.size.width = 8;
frame.size.height = 60;
frame.origin.x = 312;
frame.origin.y = 0;
[self.scrollViewBarImgView setFrame:frame];
[self.tableView addSubview:scrollViewBarImgView];
then in the - (void)scrollViewDidScroll method :
CGPoint offset = scrollView.contentOffset;
CGRect frame = self.scrollViewBarImgView.frame;
float fact = (cellHeight*numberOfRow+ indicatorBarHeight) / tableViewHeight;
frame.origin.y = offset.y + (offset.y/fact);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.1];
[self.scrollViewBarImgView setFrame:frame];
[UIView commitAnimations];
This is working for me.

iOS customize scrollbar in UITableView

In iPhone I am going to customize the scrollbar of UITableView with images.
But I didn't find correct method.
Please help me.
Thanks in advance.
firstly you have to uncheck showVerticalIndicatir and showHorizontallIndicatir in the Interface Builder.
then in the ViewDidLoad methode add :
[super viewDidLoad];
self.scrollViewBarImgView = [[UIImageView alloc] init];
UIImage *imgBar = [UIImage imageNamed:#"scroller.png"];
[self.scrollViewBarImgView setImage:imgBar];
CGRect frame = scrollViewBarImgView.frame;
frame.size.width = 8;
frame.size.height = 60;
frame.origin.x = 312;
frame.origin.y = 0;
[self.scrollViewBarImgView setFrame:frame];
[self.tableView addSubview:scrollViewBarImgView];
then in the - (void)scrollViewDidScroll methode :
CGPoint offset = scrollView.contentOffset;
CGRect frame = self.scrollViewBarImgView.frame
float fact = (cellHeight*numberOfRow+ indicatorBarHeight) / tableViewHeight;
frame.origin.y = offset.y + (offset.y/fact);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.1];
[self.scrollViewBarImgView setFrame:frame];
[UIView commitAnimations];