Xcode :How can I stop video in webview and still using webview - uiwebview

if I use
-(void)viewWillDisappear:(BOOL)animated
{
[subView loadHTMLString:nil baseURL:nil];
}
my Webview can't worked
I try to do this
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
pageControlBeingUsed = NO;
[subView loadHTMLString:nil baseURL:nil];
}
I just want to go next page with paging scrollview and stop video on next page
this my code scrollview paging
book = [[NSMutableArray alloc] initWithObjects:#"page11",#"page12",#"page13",#"page14",#"page15", nil];
for (int i = 0; i < [book count]; i++) {
CGRect frame;
frame.origin.x = self.scrollView.frame.size.height * i;
frame.origin.y = 0;
frame.size = CGSizeMake(1024,768);
subView = [[UIWebView alloc] initWithFrame:frame];
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:[book objectAtIndex:i] ofType:#"html" inDirectory:#""]];
[subView loadRequest:[NSURLRequest requestWithURL:url]];
subView.scalesPageToFit = YES;
[scrollView setBounces:NO];
[scrollView addSubview:subView];
}
scrollView.contentSize = CGSizeMake(1024 * [book count], 768);
[scrollView setFrame:CGRectMake(0, 0, 1024, 768)];
Can I play video and stop on I next page? //Please advice
sorry my English isn't well

You need to load a blank page into the UIWebView to stop the audio:
[self.webView loadRequest:NSURLRequestFromString(#"about:blank")];
or
[self.webView loadHTMLString:#"" baseURL:nil];

Thank for Advice. I try this is works for me
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
pageControlBeingUsed = NO;
CGFloat pageWidth = self.scrollView.frame.size.width;
int page = floor((self.scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
for(int i = 0; i < _pageAmount ; i++){
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i inSection:0];
[_collectionView cellForItemAtIndexPath:indexPath].backgroundColor = [UIColor clearColor];
}
currentPage = page;
if (currentPage > 0 && currentPage < [book count]-1) {
[[self.scrollView.subviews objectAtIndex:currentPage-1]reload];//
[[self.scrollView.subviews objectAtIndex:currentPage+1]reload];
}
if(self.interfaceOrientation == 1 || self.interfaceOrientation == 2){
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:page inSection:0];
[_collectionView cellForItemAtIndexPath:indexPath].backgroundColor = [UIColor redColor];
}
}

Related

how to get userintraction in uiwebview when added as sub view on a button in ios

I have a button performs some action, have added uiwebview as a sub view of the button to load a small gif animation, I can tap the button to perform the task but I needed to perform the same action when I tap the web view.
-(void)numeritsIphone4{
arrayButtonNames = #[#"Button1.png",#"Button2",#"Button3",#"Button4",#"Button5.png",#"Button6.png",#"Button7.png",#"Button8.png",#"Button9.png",#"Button10.png"];
float y = 20;
int x = 3;
int count = 0;
for (int i = 0 ; i < 10; i++)
{
count ++;
buttonsarray[i] = [UIButton buttonWithType:UIButtonTypeRoundedRect];
buttonsarray[i].frame = CGRectMake(x, y, 155, 90);
buttonsarray[i].tag = i;
[buttonsarray[i] setBackgroundImage:[UIImage imageNamed:[arrayButtonNames objectAtIndex:i]] forState:UIControlStateNormal];
[buttonsarray[i].titleLabel setFont:[UIFont fontWithName:#"Verdana" size:80]];
[buttonsarray[i] setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//buttonsarray[i].titleLabel.textAlignment = UITextAlignmentLeft;
buttonsarray[i].contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[buttonsarray[i] setTitle:[NSString stringWithFormat:#"%d",digit] forState:UIControlStateNormal];
digit ++;
character = [[UIWebView alloc]initWithFrame:CGRectMake(100, 30, 25, 25)];
NSURL *url=[[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle]pathForResource:#"Star" ofType:#"gif"]];
character.opaque = NO;
character.backgroundColor = [UIColor clearColor];
character.scrollView.scrollEnabled = NO;
[character loadRequest:[NSURLRequest requestWithURL:url]];
character.userInteractionEnabled = YES;
[buttonsarray[0] addSubview:character];
[character release];
[url release];
[buttonsarray[i] addTarget:self action:#selector(performOperation4:) forControlEvents:UIControlEventTouchUpInside];
x = x + 159;
[self.view addSubview:buttonsarray[i]];
if(count == 2)
{
count = 0;
x = 3;
y = y+ 92;
}
}
A possibility is to add a UITapGestureRecognizer to your UIWebView control and call the same function when the gesture recognizes.
NOTE: This way you have limitation if you have some buttons, links etc on your UIWebView page, that button, links might not get trigger. So give it a try and see if it helps you.

Programmatically showing new window/view when selecting UICollectionViewCell

My code right now for didSelectItemAtIndexPath is the following:
- (void)collectionView:(AFIndexedCollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
if(collectionView.index == 0){
NSLog(#"Reordenador contenido por columna %li",indexPath.item);
self.my_data = [self.my_data sortByColumn:indexPath.item skip:1 areAllNumbers:TRUE];
[self.tableView reloadData];
}else{
//show a new window with the content of the cell in a Text Field
NSLog(#"Row = %li; Column = %li - content = %#",collectionView.index,indexPath.item,[self.my_data objectInRow:collectionView.index column:indexPath.item]);
}
}
my_data = custom 2D array class object
How would I programmatically open a new popup window / new view with the content of the selected cell inside, for example, a Text Field, and 2 buttons - Save / Cancel?
Fixed with the following coding:
UIView *mySubView = [[UIView alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
[mySubView setBackgroundColor:[UIColor blackColor]];
mySubView.tag = TFIELDSUBVIEW_TAG;
self.textField = [[UITextField alloc] initWithFrame:CGRectMake(2, 10, 300, 80)];
self.textField.borderStyle = UITextBorderStyleRoundedRect;
self.textField.font = [UIFont systemFontOfSize:12];
self.textField.placeholder = [self.the_matrix objectInRow:collectionView.index column:indexPath.item];
self.textField.autocorrectionType = UITextAutocorrectionTypeNo;
self.textField.keyboardType = UIKeyboardTypeDefault;
self.textField.returnKeyType = UIReturnKeyDone;
self.textField.clearButtonMode = UITextFieldViewModeWhileEditing;
self.textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
self.textField.textAlignment = NSTextAlignmentCenter;
self.textFieldColumn = indexPath.item;
self.textFieldRow = collectionView.index;
UIButton *buttonOK = [UIButton buttonWithType:UIButtonTypeRoundedRect];
buttonOK.tag = TFIELDSUBVIEW_TAG;
[buttonOK setBackgroundImage:[UIImage imageNamed:#"ok.jpg"] forState:UIControlStateNormal];
[buttonOK addTarget:self
action:#selector(okClicked)
forControlEvents:UIControlEventTouchUpInside];
[buttonOK setTitle:#"" forState:UIControlStateNormal];
buttonOK.backgroundColor = [UIColor grayColor];
buttonOK.frame = CGRectMake(50, 100, 50, 30);
buttonOK.tintColor = [UIColor greenColor];
UIButton *buttonCANCEL = [UIButton buttonWithType:UIButtonTypeRoundedRect];
buttonCANCEL.tag = TFIELDSUBVIEW_TAG;
[buttonCANCEL addTarget:self
action:#selector(cancelClicked)
forControlEvents:UIControlEventTouchUpInside];
[buttonCANCEL setBackgroundImage:[UIImage imageNamed:#"cancel.jpg"] forState:UIControlStateNormal];
[buttonCANCEL setTitle:#"" forState:UIControlStateNormal];
buttonCANCEL.backgroundColor = [UIColor grayColor];
buttonCANCEL.frame = CGRectMake(120, 100, 75, 30);
buttonCANCEL.tintColor = [UIColor redColor];
[mySubView addSubview:buttonOK];
[mySubView addSubview:buttonCANCEL];
[mySubView addSubview:self.textField];
[self setCustomView:mySubView];
[self.view reloadInputViews];
setCustomView being the following:
-(void) setCustomView:(UIView *)customView {
NSUInteger z = NSNotFound;
if (_customView) {
z = [self.view.subviews indexOfObject:_customView];
}
if (z == NSNotFound) {
[self.view addSubview:customView];
} else {
UIView *superview = _customView.superview;
[_customView removeFromSuperview];
[superview insertSubview:customView atIndex:z];
}
_customView = customView;
}

Sprite Kit NSArray of multiple sprites?

I have 6 sprite images I am trying to add to my scene, adding each of them seems to slow everything down a lot. I figured I would need to create an NSArray in order to help with speed. Here is the array I've created, but it's only adding the first image, how can I get it to add all 6?? Thank you in advance!
myArray
NSArray *myArray = [NSArray arrayWithObjects:#"image1",#"image2",#"image3",#"image4",#"image5",#"image6", nil];
NSInteger count = [myArray count];
for (int i = 0; i < count; i++) {
if (i > 5) {
break;
}
result = [myArray objectAtIndex:i];
}
//Setting SKSpriteNodes from array.
dice = [SKSpriteNode spriteNodeWithImageNamed:[myArray objectAtIndex:result.intValue]];
Define a property in you scene:
#interface MyScene
#property (nonatomic) NSMutableArray *items;
#end
Then create a method to fill that array:
- (void)fillItems {
for (int i=0; i<10; i++) {
SKSpriteNode *d1 = [SKSpriteNode spriteNodeWithImageNamed:#"Sprite1"];
d1.position = CGPointMake(self.frame.size.width/4 + arc4random() % ((int)self.frame.size.width/2),
self.frame.size.height/2 + arc4random() % ((int)self.frame.size.height/2));
d1.color = [self randomColor];
d1.colorBlendFactor = 1.0;
d1.xScale = 0.25;
d1.yScale = 0.25;
d1.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:d1.frame.size];
//Adding SpriteKit physicsBody for collision detection
d1.physicsBody.categoryBitMask = diceCategory;
d1.physicsBody.dynamic = YES;
d1.physicsBody.contactTestBitMask = frameCategory;
d1.physicsBody.collisionBitMask = diceCategory | frameCategory;
d1.physicsBody.usesPreciseCollisionDetection = YES;
d1.name = #"Sprite1";
[self.items addObject:d1];
[self addChild:d1];
}

start at the top of the page when changing page

ı have a problem about scrollview.
my project about a newspaper.my problem about : I want to start at the
top of the page when changing page.
scrollview have 8 news.ı want to beginning at the top of the text on
the page when change 2. or 3. or.. news..
please help me about it.because ı need to deliver the project on Monday.for this reason ı
must do today or tomorrow.
code of project in here
myScrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height)];
myScrollview.pagingEnabled = YES;
myScrollview.scrollEnabled =YES;
myScrollview.clipsToBounds = NO;
myScrollview.indicatorStyle = UIScrollViewIndicatorStyleWhite;
myScrollview.showsHorizontalScrollIndicator = YES;
myScrollview.backgroundColor = [UIColor blackColor];
myScrollview.delegate = self;
NSInteger viewcount=4;
NSArray *images = [NSArray arrayWithObjects:[UIImage imageNamed:#"photo1.png"],[UIImage imageNamed:#"photo2.png"],[UIImage imageNamed:#"photo3.png"],[UIImage imageNamed:#"photo4.png"],nil];
for (int i = 0; i <viewcount; i++)
{
CGFloat x = i * self.view.frame.size.width;
subView = [[UIScrollView alloc]initWithFrame:CGRectMake(x, 0, self.view.frame.size.width, self.view.frame.size.height)];
[subView setBackgroundColor:[UIColor blackColor]];
[subView setCanCancelContentTouches:NO];
subView.clipsToBounds = NO; // default is NO, we want to restrict drawing within our scrollview
subView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
aImageView = [[UIImageView alloc ] initWithImage:[images objectAtIndex:i]];
aImageView.frame=CGRectMake(0, 0, 320, 900);
[aImageView setTag:viewcount];
[subView addSubview:aImageView];
[subView setContentSize:CGSizeMake(aImageView.frame.size.width, subView.frame.size.height)];
subView.minimumZoomScale = 1;
subView.maximumZoomScale = 9;
subView.delegate = self;
[subView setScrollEnabled:YES];
subView.contentSize = aImageView.frame.size;
[myScrollview addSubview:subView];
}
myScrollview.contentSize = CGSizeMake(self.view.frame.size.width*viewcount,self.view.frame.size.height);
[self.view addSubview:myScrollview];
https://biliyomusunuz.com

for-loop in uitableview

I am developing an application in which i am displaying data from back-end.
Now the problem is as i am filling my table with for loop, and every cell of loop is filling data by every call. suppose there are 9 entries in the database, i want them to display as per row but all the 9 rows are filling by 9 entries by overlapping each other.
As i m new to iphone development, Please help me.
this is my piece of code m trying but not succeeded.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
if(requestType == 2)
{
if (self.uniqueCityCount > 0)
{
NSString *strCity = [self.arrayCityNames objectAtIndex:section]; //#"EventData" :#"EventCity"
NSPredicate *predicateSettings = [NSPredicate predicateWithFormat:#"(EventCity = %# )",strCity];
if ([self.arrayEventDescription count]>0)
{
[self.arrayEventDescription removeAllObjects];
}
self.arrayEventDescription = [CoreDataAPIMethods searchObjectsInContext:#"EventData" :predicateSettings :#"EventCity" :YES :self.managedObjectContext];
return [self.arrayEventDescription count];
}
}
return 0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIImageView *imgEventLabel = [[UIImageView alloc]initWithFrame:CGRectMake(0, 5, 480, 22)];
imgEventLabel.image = [UIImage imageNamed:#"city_date_place.png"];
UILabel *lblCity = [[UILabel alloc]initWithFrame:CGRectMake(15, 00, 200, 22)];
lblCity.font = [UIFont systemFontOfSize:14];
lblCity.backgroundColor = [UIColor clearColor];
lblCity.tag = 301;
//lblCity.backgroundColor = [UIColor redColor];
UILabel *lblDate = [[UILabel alloc]initWithFrame:CGRectMake(200, 00, 200, 22)];
lblDate.font = [UIFont systemFontOfSize:14];
lblDate.backgroundColor = [UIColor clearColor];
lblDate.tag = 302;
//lblDate.backgroundColor = [UIColor redColor];
UILabel *lblSchool = [[UILabel alloc]initWithFrame:CGRectMake(350, 00, 400, 22)];
lblSchool.font = [UIFont systemFontOfSize:14];
lblSchool.backgroundColor = [UIColor clearColor];
lblSchool.tag = 303;
//lblSchool.backgroundColor = [UIColor redColor];
[imgEventLabel addSubview:lblCity];
[imgEventLabel addSubview:lblDate];
[imgEventLabel addSubview:lblSchool];
return imgEventLabel;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 22;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [#"" stringByAppendingFormat:#"Cell%d",indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.backgroundColor = [UIColor clearColor];
if(requestType == 2)
{
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
for (int j = 0 ; j < [self.arrayEventDescription count]; j++)
{
NSLog(#"%d",indexPath.row);
//EventData *data = [self.arrayEventDescription objectAtIndex:indexPath.row];
EventData *data = [self.arrayEventDescription objectAtIndex:j];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
cell.backgroundColor=[UIColor clearColor];
// UIView *viewDescription = [[UIView alloc]initWithFrame:CGRectMake(00, 00, 480, 35)];
////////////////////// Labels for description of city events from database ////////////////////////////
UILabel *lblEvent = [[UILabel alloc]initWithFrame:CGRectMake(15, 00, 150, 30)];
lblEvent.font = [UIFont systemFontOfSize:12];
lblEvent.backgroundColor = [UIColor clearColor];
UILabel *lblEventAtDate = [[UILabel alloc]initWithFrame:CGRectMake(200, 00, 150, 30)];
lblEventAtDate.font = [UIFont systemFontOfSize:12];
lblEventAtDate.backgroundColor = [UIColor clearColor];
UILabel *lblEventAtSchool = [[UILabel alloc]initWithFrame:CGRectMake(350, 15, 150, 30)];
lblEventAtSchool.font = [UIFont systemFontOfSize:12];
lblEventAtSchool.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:lblEvent];
[cell.contentView addSubview:lblEventAtDate];
[cell.contentView addSubview:lblEventAtSchool];
lblEvent.text = data.EventName;
//lblEventAtDate.text = data.EventDate;
lblEventAtSchool.text = data.EventPlace;
}
}
}
// Configure the cell...
return cell;
}
Don't loop through your array. Just get the element for the row that is being asked for (which is indexPath.row.)
cellForRowAtIndexPath: will be called as many times as you specify in numberOfRowsInSection:.
Just make one cell per call.

Resources