I'm getting this error and curious whats triggering it. From what I've read it's usually about animating inside viewDidLoad or blocking a UIAlertView.
1.If I comment out the scrollView block of code, the error goes away.
2.If I leave the scrollView code and comment out from 360Controller start to page One end. The warning goes away.
3.Is it because of memory overload?
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.hidden = YES;
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor grayColor];
//SCROLLVIEW Start
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
[scrollView setContentSize:CGSizeMake(1024*6, 768)];
scrollView.bounces = NO;
scrollView.pagingEnabled = YES;
scrollView.showsHorizontalScrollIndicator = YES;
scrollView.delegate = self;
[self.view addSubview:scrollView];
//SCROLLVIEW End
//Poster Vertical Scroller STart
posterVerticalScroller = [[UIScrollView alloc] initWithFrame:CGRectMake(1024*3, 0, 1024, 768)];
[posterVerticalScroller setContentSize:CGSizeMake(1024, 768*3)];
posterVerticalScroller.bounces = NO;
posterVerticalScroller.pagingEnabled = YES;
[scrollView addSubview:posterVerticalScroller];
//Poster Vertical Scroller End
//Overview Start
overView = [[OverViewController alloc] initWithNibName:nil bundle:nil];
overView.view.frame = CGRectMake(1024, 0, 1024, 768);
[scrollView addSubview:overView.view];
//OverView End
//Landing start
landingView = [[LandingViewController alloc] initWithNibName:nil bundle:nil];
landingView.view.frame = CGRectMake(0, 0, 1024, 768);
[scrollView addSubview:landingView.view];
//Landing End
//360Controller Start
rotateController * rotateAnim = [[rotateController alloc] initWithNibName:nil bundle:nil];
rotateAnim.view.frame = CGRectMake(1024*2, 0, 1024, 768);
[scrollView addSubview:rotateAnim.view];
animateHouse = [[UIImageView alloc] initWithFrame:CGRectMake(100 + 1024*2, 200, 800, 450)];
// animateHouse.animationImages = rotateImg;
//animateHouse.animationDuration = 3.0;
// animateHouse.animationRepeatCount = 1;
// [animateHouse startAnimating];
animateHouse.userInteractionEnabled = YES;
animateHouse.image = [UIImage imageNamed:#"1.png"];
[self.view addSubview:animateHouse];
//360Controller End
//Poster 1 start
poster1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"poster01.png"]];
poster1.frame = CGRectMake(0, 0, 1250, 768);
[posterVerticalScroller addSubview:poster1];
poster1Items = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"poster01_items.png"]];
poster1Items.frame = CGRectMake(0, 0, 1024, 768);
[posterVerticalScroller addSubview:poster1Items];
//Poster 1 end
//Poster 2 Start
poster2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"poster02.png"]];
poster2.frame = CGRectMake(0, 768, 1162, 768);
[posterVerticalScroller addSubview:poster2];
poster2Items = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"poster02_items.png"]];
poster2Items.frame = CGRectMake(0, 768, 1024, 768);
[posterVerticalScroller addSubview:poster2Items];
//Poster 2 End
//Poster 3 Start
poster3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"poster03.png"]];
poster3.frame = CGRectMake(0, 768*2, 1536, 768);
[posterVerticalScroller addSubview:poster3];
poster3Items = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"poster03_items.png"]];
poster3Items.frame = CGRectMake(0, 768*2, 1024,768 );
[posterVerticalScroller addSubview:poster3Items];
//Poster 3 End
//PageOne Start
UIImageView * pageOneBg = [[UIImageView alloc] initWithFrame:CGRectMake(1024*4, 0, 1024, 768)];
pageOneBg.image = [UIImage imageNamed:#"page360_landing_full.png"];
[scrollView addSubview:pageOneBg];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(1024*4+750, 520, 200, 200);
[button setTitle:#"" forState:UIControlStateNormal];
[button addTarget:self action:#selector(loadingTEst) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:button];
//PageOne End
//Page 2
UIImageView *pageTwoBG = [[UIImageView alloc] initWithFrame:CGRectMake(1024*5, 0, 1024, 768)];
pageTwoBG.image = [UIImage imageNamed:#"Page06_Full.png"];
[scrollView addSubview:pageTwoBG];
UIButton *buttonTwo = [UIButton buttonWithType:UIButtonTypeCustom];
buttonTwo.frame = CGRectMake(1024*5+0, 550, 250, 100);
[buttonTwo setTitle:#"" forState:UIControlStateNormal];
[buttonTwo addTarget:self action:#selector(loadMap) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:buttonTwo];
//Page 2 END
}
Try putting your animation code in viewDidAppear. If the animations only need to run when the view is loaded, then use a boolean to check if the view has been reloaded.
Related
I want to animate content of scrollview i have tried this for animation.
- (void)viewDidLoad {
[super viewDidLoad];
//Scroll View Created Programmatically
scrollview=[[UIScrollView alloc] initWithFrame:self.view.bounds];
scrollview.delegate=self;
scrollview.contentSize=CGSizeMake(scrollview.bounds.size.width, self.view.bounds.size.height);
[self.view addSubview:scrollview];
// Road Image Created Programmatically
backgroundImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
backgroundImageView.image = [UIImage imageNamed:#"roadds.png"];
backgroundImageView.contentMode = UIViewContentModeRedraw;
[scrollview addSubview:backgroundImageView];
// Tree top left Created Programmatically
Tree = [[UIImageView alloc] initWithFrame: CGRectMake(0, 0, 30, 50)];
Tree.image = [UIImage imageNamed:#"rsz_1rsz_tree.png"];
Tree.contentMode = UIViewContentModeTopLeft;
[scrollview addSubview:Tree];
//Tree top Right
Tree1 = [[UIImageView alloc] initWithFrame: CGRectMake(self.view.frame.size.width-30, 0, 30, 50)];
Tree1.image = [UIImage imageNamed:#"rsz_tree1.png"];
Tree1.contentMode = UIViewContentModeTopRight;
[scrollview addSubview:Tree1];
//Tree Bottom left
Tree2 = [[UIImageView alloc] initWithFrame: CGRectMake(0, self.view.frame.size.height-80, 30, 50)];
Tree2.image = [UIImage imageNamed:#"rsz_tree2.png"];
Tree2.contentMode = UIViewContentModeBottomLeft;
[scrollview addSubview:Tree2];
//Tree Bottom Right
Tree3 = [[UIImageView alloc] initWithFrame: CGRectMake(self.view.frame.size.width-30, self.view.frame.size.height-80, 30, 50)];
Tree3.image = [UIImage imageNamed:#"rsz_tree3.png"];
Tree3.contentMode = UIViewContentModeBottomRight;
[scrollview addSubview:Tree3];
// Car
car = [[UIImageView alloc] initWithFrame: CGRectMake((self.view.frame.size.width)/2+20, self.view.frame.size.height-120, 40, 60)];
car.image = [UIImage imageNamed:#"rsz_car1.png"];
car.contentMode = UIViewContentModeCenter;
[scrollview addSubview:car];
//Grass
grass = [[UIImageView alloc] initWithFrame:CGRectMake(0, (self.view.frame.size.height)/2,30, 30)];
grass.image = [UIImage imageNamed:#"rsz_grass.png"];
grass.contentMode = UIViewContentModeBottomLeft;
[scrollview addSubview:grass];
//Grass
grass1 = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width-60, (self.view.frame.size.height)/2,30, 30)];
grass1.image = [UIImage imageNamed:#"rsz_grass1.png"];
grass1.contentMode = UIViewContentModeBottomLeft;
[scrollview addSubview:grass1];
// Left Arrow
left = [[UIButton alloc] initWithFrame:CGRectMake((self.view.frame.size.width)/2+60, (self.view.frame.size.height-35),30, 30)];
[left setBackgroundImage:[UIImage imageNamed:#"rsz_arrowl.png"]forState:UIControlStateNormal];
left.contentMode = UIViewContentModeBottomRight;
[scrollview addSubview:left];
//right arrow
right = [[UIButton alloc] initWithFrame:CGRectMake((self.view.bounds.size.width)/2 - 90, (self.view.frame.size.height-35),30, 30)];
[right setBackgroundImage:[UIImage imageNamed:#"rsz_arrowr.png"]forState:UIControlStateNormal];
right.contentMode = UIViewContentModeBottomLeft;
[scrollview addSubview:right];
// For Animation
CGRect bounds = scrollview.bounds;
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:#"bounds"];
animation.duration = 10;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.fromValue = [NSValue valueWithCGRect:bounds];
bounds.origin.y += 100;
animation.toValue =[NSValue valueWithCGRect:bounds];
[scrollview.layer addAnimation:animation forKey:#"bounds"];
scrollview.bounds = bounds;
}
Add UIView to ScrollView and then add your all stuff to this view.
And add animation to this view or view's layer. Hope this will work. :)
If you want your initial position back after animation add this line
bounds.origin.y -= 100;
after
[scrollview.layer addAnimation:animation forKey:#"bounds"];
so, last five line of your viewdidLoad should as below,
bounds.origin.y += 100;
animation.toValue =[NSValue valueWithCGRect:bounds];
[scrollview.layer addAnimation:animation forKey:#"bounds"];
bounds.origin.y -= 100;
scrollview.bounds = bounds;
The scroll is covering the time and carrier , I just want it not to overlapp but the image view should finish below the carrier bar .
How can this be done.
This is my code for the same
tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320 , self.view.frame.size.height)];
self.tableView.delegate = self;
self.tableView.dataSource = self;
UIImage *image = [UIImage imageNamed:#"dora.jpeg"];
UIGraphicsBeginImageContext(CGSizeMake(320, 480));
[image drawInRect:CGRectMake(0, 0, 320, 480)];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
imageView = [[UIImageView alloc] initWithImage:image];
CGRect frame = imageView.frame;
frame.origin.y -= 130;
defaultY = frame.origin.y;
imageView.frame = frame;
self.tableView.backgroundColor = [UIColor clearColor];
UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 170)];
header.backgroundColor = [UIColor clearColor];
self.tableView.tableHeaderView = header;
[self.view addSubview:imageView];
[self.view addSubview:self.tableView];
defaultSize = CGSizeMake(50, 20);
scrollPanel = [[UIView alloc] initWithFrame:CGRectMake(-defaultSize.width, 0, defaultSize.width, defaultSize.height)];
scrollPanel.backgroundColor = [UIColor blackColor];
scrollPanel.alpha = 0.45;
Thanks
This issue can be very frustrating, and I believe it is a bug on Apple's end, especially because it shows up in their own pre-wired TableViewController from the object library.
For more info refer
iOS 7: UITableView shows under status bar
Set the origin.y of your scrollView (or table) to height of the status bar:
CGRect scrollControllFrame = scrollControll.frame;
scrollControllFrame.origin.y = [UIApplication sharedApplication].statusBarFrame.size.height;
scrollControllFrame.size.height-=[UIApplication sharedApplication].statusBarFrame.size.height;
scrollControll.frame = scrollControllFrame;
I'm using this code to show a round user's avatar on my navigation bar:
UIView *avatView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 190.0f)];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(-20, 75, 40, 40)];
imageView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
imageView.image = [UIImage imageWithData:myUtente.imgData];
imageView.layer.masksToBounds = YES;
imageView.layer.cornerRadius = 20.0;
imageView.layer.borderColor = [UIColor blueColor].CGColor;
imageView.layer.borderWidth = 1.0f;
imageView.layer.rasterizationScale = [UIScreen mainScreen].scale;
imageView.layer.shouldRasterize = YES;
imageView.clipsToBounds = YES;
[avatView addSubview:imageView];
self.navBar.titleView = avatView;
Now I'd like this avatar to act like a button, with a 2 seconds long press on it, so I've added this code:
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector(switchUser:)];
[longPressGesture setMinimumPressDuration:2.0f];
// same code as above
[avatView addGestureRecognizer:longPressGesture];
The corresponding action never gets called and I don't know why. Any idea?
Thanks.
Change the frame of avatView and imageView then gesture works like a charm.
ex:
UIView *avatView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 44)];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(80, 2, 40, 40)];
I have a UIView which creates and inserts views using GCD. It's working on iOS7 but the UIImageViews takes forever to show.
Here's the sample code that I am using.
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 120)];
for (int i = 0; i < 200; i++) {
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(77 * i, 0, 77, 88)];
[scrollView addSubview:view];
dispatch_queue_t queue = dispatch_queue_create("image", NULL);
dispatch_async(queue, ^{
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"photo#hd.png"]];
imageView.frame = CGRectMake(0, 0, 77, 88);
[view addSubview:imageView];
dispatch_async(dispatch_get_main_queue(), ^{
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
label.text = [NSString stringWithFormat:#"Name %d", i];
[label sizeToFit];
label.center = CGPointMake(38.5, 20);
[imageView addSubview:label];
});
});
[scrollView setContentSize:CGSizeMake(view.frame.size.width * (i+1), view.frame.size.height)];
}
[self.view addSubview:scrollView];
By the way, I am creating many UIViews that's why it is threaded. Around 200 views at max.
How should I make it work? The methods inside the dispatch blocks are being called, it is just the UIViews are not being displayed.
Thanks!
Im using the following codes to customize the navigationbar with an UIView. But why there is a gap in the left size of the navigationbar? ps. the gradient image is test.png.
Thanks in advance!
- (void)viewDidLoad
{
[super viewDidLoad];
// show image
UIImage *image = [UIImage imageNamed: #"test.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage: image];
[imageView setContentMode:UIViewContentModeScaleToFill];
imageView.frame = CGRectMake(0, 0, 320, 44);
// label
UILabel *tmpTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(110, 0, 100, 44)];
tmpTitleLabel.text = #"title";
tmpTitleLabel.textAlignment = UITextAlignmentCenter;
tmpTitleLabel.backgroundColor = [UIColor clearColor];
tmpTitleLabel.textColor = [UIColor whiteColor];
CGRect applicationFrame = CGRectMake(0, 0, 320, 44);
UIView * newView = [[UIView alloc] initWithFrame:applicationFrame];
[newView addSubview:imageView];
[newView addSubview:tmpTitleLabel];
self.navigationItem.titleView = newView;
}
Edit 1
Here is my test code and screen shot
- (void)viewDidLoad
{
[super viewDidLoad];
UIView * viewGreen = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
UIView * viewRed = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[viewGreen setBackgroundColor:[UIColor greenColor]];
[viewRed setBackgroundColor:[UIColor redColor]];
self.navigationItem.titleView = viewRed;
[self.view addSubview:viewGreen];
}
your code is work fine.just check the image and transparency.
To add the line at last and check again
[self.view addSubview:newView];
problem is solved by the following code
[self.navigationBar insertSubview:imageView atIndex:1];