我一直在Xcode中使用UIPageController模板来创建一个交互式书籍.
在这个应用程序中,页面加载后,每个页面都会播放不同的音频文件.
当我点击页面的一个角落时,它的效果很好(第一页的音频停止,第二页的音频开始,没有可观察到的重叠).
当我滑动手指,拖动页面时会出现问题.就像在iBooks上一样,我可以在转换过程中保持页面,看到两个页面,但这会导致两个页面的音频重叠.
最理想的情况是,我希望第一页的音频在转换开始后立即停止,第二页的音频在转换结束后立即开始(页面卷曲到达屏幕的末尾),但是其中一个仅这些就能给我一个好结果.
问题是我找不到添加[audioFromPage stop]和[audioFromPage play]的地方,以便没有重叠.
我试图将这些行添加到setViewControllers:direction:animated:completion:方法以及viewControllerAfterViewController和viewControllerBeforeViewController方法,但它们都没有工作.
你们对如何解决这个问题有什么想法吗?
我一直在尝试使用UIPageViewController在现在几天内显示3个不同的笔尖并且几乎让它工作.我仍然有一个奇怪的错误,我无法弄清楚.
基本上应用程序启动,我可以一个接一个地在3页之间滚动而没有任何问题,例如:
Page1-> Page2->第3页
然后回到开头:
Page3-> Page2->第1页.
没问题.问题是,如果我滚动,例如从Page3->第2页,然后再返回到第3页,第3页Dissappears当它放入到位.如果我滚动到第四页的位置,那么我得到Page3.这是与UIPageViewController相关的代码,nibs和UIPageViewController的委托方法:
- (void)viewDidLoad{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pageViewController.delegate = self;
[[self.pageViewController view] setFrame:[[self view] bounds]];
indexTest = 0;
Page1 *p1 = [[Page1 alloc]initWithNibName:@"Page1" bundle:nil];
p1.view.tag = 1;
Page2 *p2 = [[Page2 alloc]initWithNibName:@"Page2" bundle:nil];
p2.view.tag = 2;
Page3 *p3 = [[Page3 alloc]initWithNibName:@"Page3" bundle:nil];
p3.view.tag = 3;
NSArray *arr = [[NSArray alloc] initWithObjects:p1,nil]; …Run Code Online (Sandbox Code Playgroud) 我正在向PageViewController添加三个视图控制器,如下所示:
[pvc setViewControllers:[NSArray arrayWithObjects:svc, bvc, tvc, nil] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:^(BOOL finished) {
Run Code Online (Sandbox Code Playgroud)
}];
但是,应用程序会抛出异常并在此行停止.当我检查日志导航器时,它只是说'(lldb)'.出了什么问题?
编辑:好的,谢谢保罗.我对Objective-c很新; 如何实现这些方法来获取我的三个视图控制器之间的滑动?
这是appDelegate.m中的代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.;
UIPageViewController *pvc = [[UIPageViewController alloc] init]; // Create new PageViewController
BarsViewController *bvc = [[BarsViewController alloc] init]; // Create BarsViewController
StopwatchViewController *svc = [[StopwatchViewController alloc] init]; // Create StopwatchViewController
TimerViewController *tvc = [[TimerViewController alloc] init]; // Create TimerViewController
[pvc setViewControllers:[NSArray arrayWithObjects:svc, bvc, tvc, …Run Code Online (Sandbox Code Playgroud) 我想我不清楚Gestures如何使用UIPageViewController.我正在尝试设置一个具有四个不同"屏幕"的应用程序,并决定UIPageviewController将是一个很好的方式来促进它们之间的滑动.这是我执行设置的方法
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self setWorldWalkViewController:[EGLWorldWalkViewController new]]; //One of the content views
[self setPageView:[[UIPageViewController alloc]initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll
navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil]];
[self.pageView setViewControllers:@[self.worldWalkViewController,]//Sets the initial view to display, I think.
direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
[self.pageView setDelegate:self];
[self.pageView setDataSource:self];
self.window = [[UIWindow alloc]init];
[self.window setRootViewController:self.pageView];
currentView = WorldWalk; //Where WorldWalk is an enum value
[self.window makeKeyAndVisible];
return YES;
}
Run Code Online (Sandbox Code Playgroud)
嗯......我希望不会太久.无论如何这里是dataSource方法:
-(UIViewController *)pageViewController:(UIPageViewController *)pageViewController
viewControllerAfterViewController:(UIViewController *)viewController{
currentView += 1;
switch (currentView) {
case WorldWalk:
return [[EGLWorldWalkViewController alloc]init];
break;
case MonthlyMarch:
//There is more but …Run Code Online (Sandbox Code Playgroud) 在填写完整个屏幕后,我将点缀的UIPageControls带到了前面,我遇到了一些麻烦.
这是我目前的代码:
import UIKit
class ViewController: UIViewController, UIPageViewControllerDataSource {
//This outlet wasn't originally there. Added a UIPageControl as an attempt to solve my issue
@IBOutlet var pageControl: UIPageControl!
var pageViewController : UIPageViewController?
var pageTitles : Array<String> = ["Orc", "Elven", "Undead"]
var pageImages : Array<String> = ["Plain_Orc.png", "Plain_Elf.png", "Plain_Undead.png"]
var currentIndex : Int = 0
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.pageViewController = UIPageViewController(transitionStyle: .Scroll, navigationOrientation: .Horizontal, options: nil) …Run Code Online (Sandbox Code Playgroud) 实际上我正在尝试使用PageViewController填充图库.我成功地在视图中添加了滚动图像但是,我在页面View Controller中使用了Next和Previous按钮,但是我使用了这行代码.
- (IBAction)previousButtonPressed:(id)sender {
PageContentViewController *startingViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = @[startingViewController];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionReverse animated:NO completion:nil];
}
- (IBAction)nextButtonPressed:(id)sender {
PageContentViewController *startingViewController = [self viewControllerAtIndex:+1];
NSArray *viewControllers = @[startingViewController];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
}
Run Code Online (Sandbox Code Playgroud)
因为我在- (IBAction)nextButtonPressed:(id)发送者使用了viewControllerAtIndex:+1我只是在第一次点击按钮动作时才使按钮动作正常工作.提前致谢
我搜索了这个,但找不到任何对我有用的解决方案。如何通过 Y 更改我的页面视图点位置?
现在我把它们放在我的 ViewController 的底部。如何让他们从底部+200?
我在这里设置了我的点:
private func setupPageControl() {
let appearance = UIPageControl.appearance()
appearance.pageIndicatorTintColor = UIColor.grayColor()
appearance.currentPageIndicatorTintColor = UIColor.whiteColor()
appearance.backgroundColor = UIColor.darkGrayColor()
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试:
appearance.layer.position.y = 200
Run Code Online (Sandbox Code Playgroud)
这没有意义。如果需要,我所有的控制器代码都在这里:http : //pastebin.com/1hLRFPsR
我在常规UIViewController中的Container内有一个UIPageViewController(自定义).我需要能够在每次更改页面时调用一个事件,但是如果它确实发生了变化,而不仅仅是一半或类似的事情.
使用:
func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController?
Run Code Online (Sandbox Code Playgroud)
是不可靠的,每次都不会因为某些原因而被调用.
如果您的答案包含有关willTransitionToViewControllers或didFinishAnimating的任何内容,请详细说明,而不仅仅是提及它们,因为我已经知道它们存在但不明白使用它们的正确方法.
谢谢
我正在使用 an UIPageViewController,我的目的是在单击UIButton其中一个UIViewController. 我已经用谷歌搜索了我的问题并找到了一些类似的线索,但我无法弄清楚答案。
例如,我的第二个按钮UIViewController vc2应将视图更改为vc3。
根页面视图控制器
import UIKit
class RootPageViewController: UIPageViewController, UIPageViewControllerDataSource {
lazy var viewControllerList:[UIViewController] = {
let sb = UIStoryboard(name: "Main", bundle: nil)
let vc1 = sb.instantiateViewController(withIdentifier: "timelineView")
let vc2 = sb.instantiateViewController(withIdentifier: "mainView")
let vc3 = sb.instantiateViewController(withIdentifier: "addView")
return [vc1, vc2, vc3]
}()
override func viewDidLoad() {
super.viewDidLoad()
self.dataSource = self
let secondViewController = viewControllerList[1]
self.setViewControllers([secondViewController], direction: .forward, animated: false, completion: nil)
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore …Run Code Online (Sandbox Code Playgroud) 一切正常,但点不显示。我的代码是...
import UIKit
class MyPageViewController: UIPageViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
dataSource = self
if let firstViewController = orderedViewControllers.first {
setViewControllers([firstViewController],
direction: .forward,
animated: true,
completion: nil)
}
}
private(set) lazy var orderedViewControllers: [UIViewController] = {
return [self.newColoredViewController(color: ""),
self.newColoredViewController(color: "Second"),
self.newColoredViewController(color: "Third")]
}()
private func newColoredViewController(color: String) -> UIViewController {
return UIStoryboard(name: "Main", bundle: nil) .
instantiateViewController(withIdentifier: "\(color)ViewController")
}
}
// MARK: UIPageViewControllerDataSource
extension MyPageViewController: UIPageViewControllerDataSource {
func pageViewController(_ …Run Code Online (Sandbox Code Playgroud) ios ×9
swift ×5
xcode ×3
button ×1
cocoa-touch ×1
containers ×1
navigation ×1
nib ×1
objective-c ×1
uikit ×1
xcode6 ×1