I have a scrollView with paging. I declare it:
if(_fullPosterScroll == nil) _fullPosterScroll = [[UIScrollView alloc] initWithFrame:rc];
[_fullPosterScroll setDelegate:self];
[_fullPosterScroll setBackgroundColor:[UIColor blackColor]];
[_fullPosterScroll setCanCancelContentTouches:NO];
_fullPosterScroll.indicatorStyle = UIScrollViewIndicatorStyleWhite;
_fullPosterScroll.clipsToBounds = NO;
_fullPosterScroll.pagingEnabled = YES;
_fullPosterScroll.alwaysBounceHorizontal = NO;
_fullPosterScroll.directionalLockEnabled = YES;
And after a tap i call a method:
[_fullPosterScroll setContentOffset:CGPointMake(_selectedPosterPosition*(_fullPosterScroll.frame.size.width), 0) animated:YES];
NSLog(#"%f",_fullPosterScroll.contentOffset.y);
Why after that in Log i have for example 225.00 ?! This should be 0!
I can't see anything wrong with the code you've posted, but you should check to make sure that setContentOffset isn't triggering any delegate methods that are changing offset.
Also, Apple have a sample project, PageControl, that does exactly what you want, so you should look at that if you want a complete example.
Related
I am using the PhoneGap ExternalScreen plugin, but I have modified it slightly to be able to support multiple resolutions. I got some tips from Matt Gemmel's post on iPadVGAOutput (http://mattgemmell.com/2010/06/01/ipad-vga-output/) Here is what my code looks like:
- (void) toggleResolution:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
self.callbackID = [arguments pop];
if ([[UIScreen screens] count] > 1){
externalScreen = [[[UIScreen screens] objectAtIndex:1] retain];
screenModes = [externalScreen.availableModes retain];
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:#"External Display Size"
message:#"Choose a size for the external display."
delegate:self
cancelButtonTitle:nil
otherButtonTitles:nil] autorelease];
for (UIScreenMode *mode in screenModes){
CGSize modeScreenSize = mode.size;
[alert addButtonWithTitle:[NSString stringWithFormat:#"%.0f x %.0f pixels", modeScreenSize.width, modeScreenSize.height]];
}
[alert show];
} else {
PluginResult* pluginResult = [PluginResult resultWithStatus:PGCommandStatus_ERROR messageAsString:WEBVIEW_UNAVAILABLE];
[self writeJavascript: [pluginResult toErrorCallbackString:self.callbackID]];
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
UIScreenMode *desiredMode = [screenModes objectAtIndex:buttonIndex];
externalScreen.currentMode = desiredMode;
externalWindow.screen = externalScreen;
[screenModes release];
CGRect rect = CGRectZero;
rect.size = desiredMode.size;
externalWindow.frame = rect;
externalWindow.clipsToBounds = YES;
externalWindow.hidden = NO;
[externalWindow makeKeyAndVisible];
PluginResult* pluginResult = [PluginResult resultWithStatus:PGCommandStatus_OK messageAsString:WEBVIEW_OK];
[self writeJavascript: [pluginResult toSuccessCallbackString:self.callbackID]];
}
The resolution is changing just fine, but the content is not being constrained inside of the correct dimensions. An example is as follows:
When the second screen is originally loaded (at 1920x1080), it looks like this: http://cl.ly/F5IV
After changing the resolution to 1280x720, it looks like this: http://cl.ly/F41K
I am relatively new to Objective-C, but am quickly picking it up. Any pointers on solving my problem and/or improving the code altogether would be great. Thanks!
Andrew
EDIT: I also wanted to clarify, I am not manually setting any width/height on any of the views and/or CSS that is being displayed.
Since no one found it, I started to dig into the Objective-C and solved it. I had to add the following to the alertView method:
webView.frame = rect;
As your solution didn't work for me I'll put my solution to this here. I was getting the black bars around the view too although the screens dimension was detected right. I just had to set
[externScreen setOverscanCompensation: UIScreenOverscanCompensationInsetApplicationFrame];
and the bars were gone.
I am using an applicationMusicPlayer and when i try to change the volume appear the visual notification, as shown in the picture.
Here the code I am using:
[MPMusicPlayerController applicationMusicPlayer] setVolume:newVolune];
Anyone knows how to hide this notification?
I don't know where the docs says so, but if you add a MPVolumeView view to your app the system volume overlay goes away. Even if it is not visible:
- (void) viewDidLoad
{
[super viewDidLoad];
MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame: CGRectZero];
[self.view addSubview: volumeView];
[volumeView release];
...
}
You can use the hardware volume buttons, the setVolume method or directly interact with the control (if visible) that the overlay doesn't show up.
For iOS6 I had to set an image with alpha 0 and non-zero size to the MPVolumeView's image fields in order to get the default volume change notification to disappear.
// hide the hardware volume slider
UIImage *thumb = [[UIImage alloc] initWithCIImage:[UIImage imageNamed:#"volumeHider"].CIImage scale:0.0 orientation:UIImageOrientationUp];
MPVolumeView *hwVolume = [[MPVolumeView alloc] initWithFrame:self.frame];
[hwVolume setUserInteractionEnabled:NO];
hwVolume.showsRouteButton = NO;
[hwVolume setVolumeThumbImage:thumb forState:UIControlStateNormal];
[hwVolume setMinimumVolumeSliderImage:thumb forState:UIControlStateNormal];
[hwVolume setMaximumVolumeSliderImage:thumb forState:UIControlStateNormal];
[self addSubview:hwVolume];
This made the MPVolumeView be "visible" on the screen, but invisible to the user.
I encountered the same issue recently. Instead of adding the MPVolumeView to current view controller's view, I add it to the application's window once at the start of the app:
CGRect rect = CGRectMake(-500, -500, 0, 0);
MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame:rect];
[self.window addSubview:volumeView];
This works in both iOS 7 and 8.
Swift 3
You can hide the System MPVolumeView using
override func viewDidLoad() {
super.viewDidLoad()
let volumeView = MPVolumeView(frame: CGRect.zero)
self.view.addSubview(volumeView)
}
I had success with this in iOS 6. Although it wouldn't perform well. It caused quite a bit of lag when sliding the thumbImage. I did have to take out the last 2 lines of code in order for this to work.
[volumeView release];
...
For me, on iOS 7, none of above solutions worked. Here is how I did it:
_volume = [[MPVolumeView alloc] initWithFrame: CGRectMake(-100,-100,16,16)];
_volume.showsRouteButton = NO;
_volume.userInteractionEnabled = NO;
[self.view addSubview:_volume];
[_volume release];
That is, simply set MPVolumeView's frame to an off-screen location such as (-100,-100).
In order to make my custom UIImagePickerSourceTypeCamera, I had to do this:
pickerOne = [[UIImagePickerController alloc] init];
pickerOne.delegate = self;
pickerOne.sourceType = UIImagePickerControllerSourceTypeCamera;
pickerOne.showsCameraControls = NO;
pickerOne.navigationBarHidden = YES;
pickerOne.toolbarHidden = YES;
pickerOne.wantsFullScreenLayout = YES;
But now, when I take a picture like this:
[cameraButton addTarget:pickerOne
action:#selector(takePicture)
forControlEvents:UIControlEventTouchUpInside];
it doesn't show the shutter when you take the picture. Is there a way to show it programmatically?
It is possible. The trick is to do the following:
Enable the camera controls on initializing the picker (this will enable the shutter view).
pickerOne.showsCameraControls = YES;
Overlay the camera controls with your own view which has the cameraButton
In your takePicture: method do the following:
pickerOne.showsCameraControls = NO;
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.0]];
[pickerOne takePicture];
In the imagePickerController:didFinishPickingMediaWithInfo: method do the following:
pickerOne.showsCameraControls = YES; // perform on main thread
There is no way to control the "shutter" affect. You can however create your own image and add the affect in there.
hi I have a problem I made an application based on apples sample app called photoscroller and i want to add a login screen.but when i add it the showed view move upward 10-15 pixels and the main window is visible underneath.I ask why?
Parts of my code:
at view did load:
InfoViewController *infoView = [[InfoViewController alloc] initWithNibName:nil bundle:nil];
self.view = infoView.view;
[infoView release];
then later after validating the login:
CGRect pagingScrollViewFrame = [self frameForPagingScrollView];
pagingScrollView = [[UIScrollView alloc] initWithFrame:pagingScrollViewFrame];
pagingScrollView.pagingEnabled = YES;
pagingScrollView.backgroundColor = [UIColor blackColor];
pagingScrollView.showsVerticalScrollIndicator = NO;
pagingScrollView.showsHorizontalScrollIndicator = NO;
pagingScrollView.contentSize = [self contentSizeForPagingScrollView];
pagingScrollView.delegate = self;
self.view = pagingScrollView;
...
I do not know why is pushed upward when i add other view.
thank for every answer
Could you past the method - (CGRect) frameForPagingScrollView, without that method it's bit harder to understand your code.
But i guess the self.view.frame and the CGRect returned from that method differ.
Further guess would be, that the difference are not 10-15 pixels, but 20 pixels (for the height of the UIStatusBar), which might be enabled in your .xib-File but is actually not displayed.
So Instruments tells me I have three memory leaks originating in this method (specifically, it points out the line:
[self.view addSubview:menuBar.view];
I can't see a leak and am racking my brains. I'm keeping a reference to the menuBar object and am releasing it. Anyone smarter than me that can explain? Is it a coincidence that I have three menubar items in my XIB and I'm getting three leaks?
Here is the entire method:
//
root vc calls to toggle display state of menu bar on screen
-(IBAction) showToolBar {
//if no toolbar exists, create one and add it to the view
if (!menuBarView) {
MenuBarViewController *menuBar = [[MenuBarViewController alloc] initWithNibName:#"MenuBarViewController" bundle:nil];
menuBar.book = self.selectedTitleDeck;
menuBar.booksArray = self.allTitleDeck;
self.menuBarView = menuBar;
[self.view addSubview:menuBar.view];
[menuBar release];
}
CGRect frame = menuBarView.view.frame;
[UIView beginAnimations:nil context:NULL];
if (self.toolBarIsDisplayed == NO) {
//show the toolbar
frame.origin.y = 725;
self.toolBarIsDisplayed = YES;
} else if (self.toolBarIsDisplayed == YES) {
//hide the toolbar
frame.origin.y = 788;
self.toolBarIsDisplayed = NO;
}
self.menuBarView.view.frame = frame;
[UIView commitAnimations];
}
addSubview: retains the view passed into it (see the reference). Once you call addSubView, you can release that view, like:
MenuBarViewController *menuBar = [[MenuBarViewController alloc] initWithNibName:#"MenuBarViewController" bundle:nil];
menuBar.book = self.selectedTitleDeck;
menuBar.booksArray = self.allTitleDeck;
self.menuBarView = menuBar;
[self.view addSubview:menuBar.view];
[menuBar.view release];
[menuBar release];
}
Show us what happens in MenuBarViewController's dealloc method. I suspect you are forgetting to release its instance variables.
As suggested in the comments to my question, the problem was not in the code but in running my app in the simulator and trying to detect memory leaks.
When Instruments is run against the code on the device, no leaks are reported.
My consolation prize is a far more profound understanding of memory management unearthed in two days of trying to locate a leak that didn't exist.
Thanks to all for your advice, much appreciated.