我有一段代码,允许您使用放大手势放大和缩小带有渐变的圆。如果我将手指放在屏幕中间并进行缩放,效果很好,但如果我将手指放在屏幕边缘并执行放大手势,我希望它放大手指之间的点。目前,它仍然以屏幕中心为中心进行放大。
如何修改我的代码以允许用户在手指放置之间以 CGPoint 为中心?
struct ContentView: View {
@GestureState var magnificationState = MagnificationState.inactive
@State var viewMagnificationState = CGFloat(1.0)
var magnificationScale: CGFloat {
return viewMagnificationState * magnificationState.scale
}
var body: some View {
let gradient = Gradient(colors: [.red, .yellow, .green, .blue, .purple, .red, .yellow, .green, .blue, .purple, .red, .yellow, .green, .blue, .purple])
let magnificationGesture = MagnificationGesture()
.updating($magnificationState) { value, state, transaction in
state = .zooming(scale: value)
}.onEnded { value in
self.viewMagnificationState *= value
}
Circle()
.fill(
RadialGradient(gradient: gradient, center: .center, startRadius: …
Run Code Online (Sandbox Code Playgroud) 我使用的是Windows 10 Pro 64bit.
我的显示器(32英寸)的原始分辨率为3820*2160像素.
一旦我使用基于Java的应用程序,我就会遇到字体,按钮等的放大问题.通常它们太小了.
我知道我可以将所有元素的整体缩放比例改为100%以上.但这导致了字体等模糊的事实.
你有解决方案吗?
如何禁用在UIWebView上触摸时出现的放大镜?我不想禁用用户交互,但我不希望webview显示缩放玻璃.有任何想法吗?
Windows 7在其控制面板,外观和个性化,显示设置上添加了将文本和其他项目放大125%或150%的功能.
完成后,我的Delphi 2009程序的表单和对话框的一些内容被切断.
我需要做些哪些更改才能确保在Windows 7上的任何放大设置下,我的所有表单和对话框都能正常显示.
如何将放大镜添加到自定义控件?控制是UIView的孩子.(这是一个UIWebView - 但原生放大功能在某些页面上不起作用.)
更新:
也许可以在UIWebView上强制绘制放大镜?
我有一个渲染大的图像,需要缩放用户光标下的部分.
我的图像在Grid中,并以这种方式在XAML中定义:
<Grid x:Name="RootImgGrid" Background="#FF333333" >
<Viewbox x:Name="imgViewBox" Margin="1,1,1,1" Stretch="Fill" >
<Canvas x:Name="imgCanvas" ClipToBounds="True" Width="{Binding ElementName=RootImgGrid, Path=ActualWidth}" Height="{Binding ElementName=RootImgGrid, Path=ActualHeight}">
<Image x:Name="imgObj" MouseWheel="img_MouseWheel" Cursor="Hand" MouseMove="Img_MouseMove" MouseDown="Img_MouseDown" MouseUp="Img_MouseUp" >
<Image.RenderTransform>
<TransformGroup x:Name="imgTransformGroup">
<ScaleTransform x:Name="imgScaleTransform"></ScaleTransform>
<TranslateTransform x:Name="imgTranslateTransform"></TranslateTransform>
</TransformGroup>
</Image.RenderTransform>
<Image.LayoutTransform>
<RotateTransform x:Name="imgRotateTransform"></RotateTransform>
</Image.LayoutTransform>
</Image>
</Canvas>
</Viewbox>
</Grid>
Run Code Online (Sandbox Code Playgroud)
我有一个缩放区域应该出现在我的光标下缩放2倍的图像.
<Viewbox x:Name="imgViewBoxMagnifier" Width="400" Height="90">
<Canvas x:Name="imgCanvasMagnifier" Width="400" Height="90">
<Canvas.Clip>
<RectangleGeometry Rect="0,0,400,90" />
</Canvas.Clip>
<Image x:Name="imgMagnifier" Margin="2" Width="400" Height="90">
<Image.RenderTransform>
<TransformGroup x:Name="imgMagnifierTransformGroup">
<ScaleTransform x:Name="imgMagnifierScaleTransform"></ScaleTransform>
<TranslateTransform x:Name="imgMagnifierTranslateTransform"></TranslateTransform>
</TransformGroup>
</Image.RenderTransform>
<Image.LayoutTransform>
<RotateTransform x:Name="imgMagnifierRotateTransform"></RotateTransform>
</Image.LayoutTransform>
</Image>
</Canvas>
</Viewbox> …
Run Code Online (Sandbox Code Playgroud) 我在IB中编写了一个NSScrollView并选中了该allow magnification
框.这实际上是做什么的?
这是我在Apples示例中发现的,其中实现了手动放大:
- (void)magnifyWithEvent:(NSEvent *)event {
[resultsField setStringValue:
[NSString stringWithFormat:@"Magnification value is %f", [event magnification]]];
NSSize newSize;
newSize.height = self.frame.size.height * ([event magnification] + 1.0);
newSize.width = self.frame.size.width * ([event magnification] + 1.0);
[self setFrameSize:newSize];
}
Run Code Online (Sandbox Code Playgroud)
使用allow magnification
也会调整视图中的所有内容,因此不能像上面那样设置帧大小.
这就像scaleUnitSquareToSize:
用来操纵坐标系一样吗?
objective-c nsscrollview magnification coordinate-transformation
我有一个NSScrollView与自定义NSImageView作为其在xib文件中设置的文档视图.当我想放大NSScrollView时,我的问题出现了.我希望它的行为类似于Mac上的预览应用程序,我可以让它放大得很好,但我希望它以光标为中心点进行放大.
我在自定义NSScrollView类中有这个代码:
//Informs the receiver that the user has begun a pinch gesture.
- (void)magnifyWithEvent:(NSEvent *)event {
NSPoint conViewPoint =[[self contentView] convertPoint:[event locationInWindow] fromView:nil];
[self setMagnification:[event magnification]+[self magnification] centeredAtPoint:conViewPoint];
}
Run Code Online (Sandbox Code Playgroud)
这可行,但它也会导致滚动视图在放大时向下滚动(尽管它根本不会向侧面移动).在没有从触控板抬起的情况下多次放大和缩小时更加明显.
类似的问题似乎是在这个问题,但我使用的是捏手势,而不是按钮.我一直试图偏移y轴滚动,正如该问题所建议的那样
[[self documentView] scrollPoint:scrollPoint]
Run Code Online (Sandbox Code Playgroud)
但我无法找到scrollPoint
该帐户的工作公式,以便更改内容视图边界以将光标下的点保持在同一位置.所以,我想知道是否有更合适的方法,或者是否真的需要滚动,我只需要弄清楚数学.
感谢您的帮助
编辑:
所以我终于找到了滚动数学.这需要一段时间和更复杂的尝试,但最终非常简单:
- (void)magnifyWithEvent:(NSEvent *)event {
NSPoint docViewPoint =[[self documentView] convertPoint:[event locationInWindow] fromView:nil];
NSPoint docRectOri=[self documentVisibleRect].origin;
float widthGapSize=-docRectOri.x;
float heightGapSize=-docRectOri.y;
if([event phase]==NSEventPhaseBegan){
startDocPoint=docViewPoint;
startPoint.x=(docViewPoint.x+widthGapSize)*[self magnification];
startPoint.y=(docViewPoint.y+heightGapSize)*[self magnification];
}
scrollPoint.x=startDocPoint.x-(startPoint.x/[self magnification]);
scrollPoint.y=startDocPoint.y-(startPoint.y/[self magnification]);
[self setMagnification:[event magnification]+[self magnification] centeredAtPoint:docViewPoint];
[[self documentView] …
Run Code Online (Sandbox Code Playgroud) 使用Android 4.1.1谷歌浏览器,当我尝试点击靠近的小链接时,这些链接的放大视图会弹出.
有没有办法在设置或CSS/meta标签中停用它?
这不是一个答案,会得到一个正确的答案,但我会问它反正:
是否可以对图像进行磁化或放大,使其不会模糊?
例如,这不应该发生,像素不应该相互模糊,而应该放大块像素.maginification: block;
在CSS或HTML中是否有类似或类似的东西,或者JS填充?
我想做与滑块相同的事情:
@State itemSize: CGFloat = 55.60
....
Text("ItemSize: \(itemSize)")
Slider(value: $itemSize, in: 45...120)
Run Code Online (Sandbox Code Playgroud)
但有放大手势。
我为此创建了修改器:
import SwiftUI
@available(OSX 11.0, *)
public extension View {
func magnificationZoomer(value: Binding<CGFloat>,min: CGFloat, max: CGFloat) -> some View
{
self.modifier( MagnificationZoomerMod(minZoom: min, maxZoom: max, zoom: value) )
}
}
@available(OSX 11.0, *)
public struct MagnificationZoomerMod: ViewModifier {
let minZoom: CGFloat
let maxZoom: CGFloat
@Binding var zoom: CGFloat
public func body (content: Content) -> some View
{
content
.gesture(
MagnificationGesture()
.onChanged() { val in
let magnification …
Run Code Online (Sandbox Code Playgroud)